home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / FAQSYS18.ZIP / FAQS.DAT / TIFF5_0.DOC < prev    next >
Encoding:
Text File  |  1996-01-04  |  174.4 KB  |  4,687 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.           An Aldus/Microsoft Technical Memorandum:  8/8/88    Page 1
  8.           An Aldus/Microsoft Technical Memorandum:  8/8/88    Page 1
  9.           
  10.           
  11.           
  12.           Preface
  13.           
  14.           
  15.           This memorandum  has been prepared jointly by Aldus and Microsoft
  16.           in conjunction  with leading scanner vendors and other interested
  17.           parties.   This document  does not  represent a commitment on the
  18.           part of  either Microsoft  or Aldus  to provide  support for this
  19.           file format  in any  application.   When responding  to  specific
  20.           issues raised  in this memo, or when requesting additional tag or
  21.           field assignments, please address your correspondence to either:
  22.           
  23.                Developers_ Desk    Windows Marketing Group
  24.                Aldus Corporation   Microsoft Corporation
  25.                411 First Ave. South     16011 NE 36th Way
  26.                Suite 200 Box 97017
  27.                Seattle, WA  98104  Redmond, WA  98073-9717
  28.                (206) 622-5500 (206) 882-8080
  29.           
  30.           
  31.           
  32.           Revision Notes
  33.           
  34.           This revision  replaces _TIFF  Revision 4._   Sections in italics
  35.           are new or substantially changed in this revision.  Also new, but
  36.           not in italics, are Appendices F, G, and H.
  37.           
  38.           The major enhancements in TIFF 5.0 are:
  39.           
  40.           1.   Compression of  grayscale and  color images, for better disk
  41.           space utilization.  See Appendix F.
  42.           
  43.           2.   TIFF Classes_restricted  TIFF subsets  that can simplify the
  44.           job of  the TIFF  implementor.   You may  wish to scan Appendix G
  45.           before reading the rest of this document.   In fact, you may want
  46.           to use  Appendix G as your main guide, and refer back to the main
  47.           body of  the specification  as needed for details concerning TIFF
  48.           structures and field definitions.
  49.           
  50.           3.   Support for  _palette color_   images.  See the TIFF Class P
  51.           description  in   Appendix  G,   and  the   new  ColorMap   field
  52.           description.
  53.           
  54.           4.   Two new  tags that  can be  used to  more fully  define  the
  55.           characteristics of  full color  RGB data, and thereby potentially
  56.           improve the quality of color image reproduction.  See Appendix H.
  57.           
  58.           The organization  of the  document has also changed slightly.  In
  59.           particular, the  tags are  listed in  alphabetical order,  within
  60.           several categories, in the main body of the specification.
  61.           
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.           TIFF 5.0                                          page 2
  72.           TIFF 5.0                                          page 2
  73.  
  74.  
  75.           As always,  every attempt  has been  made to add functionality in
  76.           such a  way as  to minimize  incompatibility problems  with older
  77.           TIFF software.   In  particular, many  TIFF  5.0  files  will  be
  78.           readable even  by older  applications that  assume TIFF 4.0 or an
  79.           earlier version  of the  specification.   One exception  is  with
  80.           files that  use the  new TIFF  5.0 LZW  compression scheme.   Old
  81.           applications will  have to  give up  in this case, of course, and
  82.           will do so _gracefully_ if they have been following the rules.
  83.           
  84.           We  are  grateful  to  all  of  the  draft  reviewers  for  their
  85.           suggestions.   Especially helpful  were Herb  Weiner  of  Kitchen
  86.           Wisdom  Publishing   Company,  Brad  Pillow  of  TrueVision,  and
  87.           engineers from Hewlett Packard and Quark.  Chris Sears of Magenta
  88.           Graphics provided information which is included as Appendix H.
  89.           
  90.           
  91.           Abstract
  92.           
  93.           This document  describes TIFF,  a tag  based file  format that is
  94.           designed to promote the interchange of digital image data.
  95.           
  96.           The fields  were defined  primarily with  desktop publishing  and
  97.           related applications  in mind, although it is possible that other
  98.           sorts of imaging applications may find TIFF to be useful.
  99.           
  100.           The general  scenario for  which TIFF  was invented  assumes that
  101.           applications software  for scanning  or painting  creates a  TIFF
  102.           file, which  can then  be read and incorporated into a _document_
  103.           or _publication_   by an application such as a desktop publishing
  104.           package.
  105.           
  106.           TIFF is  not a printer language or page description language, nor
  107.           is it intended to be a general document interchange standard. The
  108.           primary design  goal was  to provide  a rich  environment  within
  109.           which the exchange of image data between application programs can
  110.           be accomplished.   This  richness is  required in  order to  take
  111.           advantage of  the varying  capabilities of  scanners and  similar
  112.           devices.  TIFF is therefore designed to be a superset of existing
  113.           image file  formats for  _desktop_   scanners (and paint programs
  114.           and anything  else that  produces images with pixels in them) and
  115.           will be enhanced on a continuing basis as new capabilities arise.
  116.           A high  priority has been given to structuring the data in such a
  117.           way as  to minimize  the pain  of future  additions.    TIFF  was
  118.           designed to be an extensible interchange format.
  119.           
  120.           Although TIFF  is claimed  to be  in some sense a rich format, it
  121.           can easily  be used for simple scanners and applications as well,
  122.           since the  application developer  need only be concerned with the
  123.           capabilities that he requires.
  124.           
  125.           TIFF is intended to be independent of specific operating systems,
  126.           filing systems,  compilers, and processors.  The only significant
  127.           assumption is  that the  storage medium supports something like a
  128.           _file,_   defined as  a sequence  of 8-bit bytes, where the bytes
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.           TIFF 5.0                                          page 3
  139.           TIFF 5.0                                          page 3
  140.  
  141.  
  142.           are numbered  from 0  to N.   The  largest possible  TIFF file is
  143.           2**32 bytes  in length.   Since TIFF uses pointers (byte offsets)
  144.           quite liberally,  a TIFF  file is  most easily read from a random
  145.           access device  such as a hard disk or flexible diskette, although
  146.           it should  be possible  to read  and write TIFF files on magnetic
  147.           tape.
  148.           
  149.           The recommended  MS-DOS, UNIX,  and OS/2  file extension for TIFF
  150.           files is  _.TIF._   The recommended Macintosh filetype is _TIFF_.
  151.           Suggestions for  conventions in  other computing environments are
  152.           welcome.
  153.           
  154.           
  155.           1) Structure
  156.           
  157.           In TIFF, individual fields are identified with a unique tag. This
  158.           allows particular fields to be present or absent from the file as
  159.           required by the application.  For an explanation of the rationale
  160.           behind using a tag structure format, see Appendix A.
  161.           
  162.           A TIFF file begins with an 8-byte _image file header_ that points
  163.           to one  or  more  _image  file  directories._    The  image  file
  164.           directories contain  information about  the images,  as  well  as
  165.           pointers to the actual image data.
  166.           
  167.           See Figure 1.
  168.           
  169.           We will now describe these structures in more detail.
  170.           
  171.           Image file header
  172.           
  173.           A TIFF  file begins  with an 8-byte image file header, containing
  174.           the following information:
  175.           
  176.           Bytes 0-1:     The first  word of  the file  specifies  the  byte
  177.           order used within the file.  Legal values are:
  178.           
  179.                     _II_ (hex 4949)
  180.                     _MM_ (hex 4D4D)
  181.           
  182.                In the  _II_   format,  byte  order  is  always  from  least
  183.           significant to  most significant,  for  both  16-bit  and  32-bit
  184.           integers.   In the  _MM_   format, byte order is always from most
  185.           significant to  least significant,  for both  16-bit  and  32-bit
  186.           integers.   In both  formats, character  strings are  stored into
  187.           sequential byte locations.
  188.           
  189.                All  TIFF   readers  should  support  both  byte  orders_see
  190.           Appendix G.
  191.           
  192.           Bytes 2-3 The second  word of  the  file  is  the  TIFF  _version
  193.           number._   This number, 42 (2A in hex), is not to be equated with
  194.           the current  Revision of  the TIFF  specification.   In fact, the
  195.           TIFF version  number (42)  has never  changed, and probably never
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.           TIFF 5.0                                          page 4
  206.           TIFF 5.0                                          page 4
  207.  
  208.  
  209.           will.   If it  ever does,  it means that TIFF has changed in some
  210.           way so  radical that  a TIFF  reader should  give up immediately.
  211.           The number 42 was chosen for its deep philosophical significance.
  212.           It can and should be used as additional verification that this is
  213.           indeed a TIFF file.
  214.           
  215.                A TIFF  file does  not have  a real version/revision number.
  216.           This was  an explicit,  conscious design  decision.  In many file
  217.           formats, fields  take on different meanings depending on a single
  218.           version number.   The  problem is that as the file format _ages,_
  219.           it becomes  increasingly difficult  to document which fields mean
  220.           what in  a given  version, and older software usually has to give
  221.           up if  it encounters  a file  with a  newer version  number.   We
  222.           wanted TIFF  fields to have a permanent and well-defined meaning,
  223.           so that  _older_ software  can usually  read _newer_  TIFF files.
  224.           The bottom line is lower software release costs and more reliable
  225.           software.
  226.           
  227.           Bytes 4-7 This long  word contains  the offset  (in bytes) of the
  228.           first Image File Directory.  The directory may be at any location
  229.           in the  file after  the header but must begin on a word boundary.
  230.           In particular,  an Image File Directory may follow the image data
  231.           it describes.   Readers must simply follow the pointers, wherever
  232.           they may lead.
  233.           
  234.                (The term  _byte offset_  is always used in this document to
  235.           refer to  a location  with respect  to the beginning of the file.
  236.           The first byte of the file has an offset of 0.)
  237.           
  238.           
  239.           Image file directory
  240.           
  241.           An Image  File Directory  (IFD) consists of a 2-byte count of the
  242.           number of  entries (i.e.,  the number  of fields),  followed by a
  243.           sequence of 12-byte field entries, followed by a 4-byte offset of
  244.           the next  Image File  Directory (or 0 if none).  Do not forget to
  245.           write the 4 bytes of 0 after the last IFD.
  246.           
  247.           Each 12-byte IFD entry has the following format:
  248.           
  249.           Bytes 0-1 contain the Tag for the field.
  250.           Bytes 2-3 contain the field Type.
  251.           Bytes 4-7 contain the  Length (_Count_  might have  been a better
  252.           term) of the field.
  253.           Bytes 8-11     contain the  Value Offset,  the  file  offset  (in
  254.           bytes) of  the Value  for the  field.   The Value  is expected to
  255.           begin on  a word  boundary; the  corresponding Value  Offset will
  256.           thus be  an even  number.  This file offset may point to anywhere
  257.           in the file, including after the image data.
  258.           
  259.           The entries  in an  IFD must be sorted in ascending order by Tag.
  260.           Note that this is not the order in which the fields are described
  261.           in this  document.   For a  numerically ordered list of tags, see
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.           TIFF 5.0                                          page 5
  273.           TIFF 5.0                                          page 5
  274.  
  275.  
  276.           Appendix E.  The Values to which directory entries point need not
  277.           be in any particular order in the file.
  278.           
  279.           In order  to save time and space, the Value Offset is interpreted
  280.           to contain  the Value  instead of  pointing to  the Value  if the
  281.           Value fits  into 4  bytes.  If the Value is less than 4 bytes, it
  282.           is left-justified within the 4-byte Value Offset, i.e., stored in
  283.           the lower-numbered bytes.  Whether or not the Value fits within 4
  284.           bytes is  determined by  looking at  the Type  and Length  of the
  285.           field.
  286.           
  287.           The Length  is specified in terms of the data type, not the total
  288.           number of bytes.  A single 16-bit word (SHORT) has a Length of 1,
  289.           not 2,  for example.   The  data  types  and  their  lengths  are
  290.           described below:
  291.           
  292.           1 = BYTE  An 8-bit unsigned integer.
  293.           2 = ASCII 8-bit bytes  that store ASCII codes; the last byte must
  294.           be null.
  295.           3 = SHORT A 16-bit (2-byte) unsigned integer.
  296.           4 = LONG  A 32-bit (4-byte) unsigned integer.
  297.           5 = RATIONAL   Two LONG_s:  the first represents the numerator of
  298.           a fraction, the second the denominator.
  299.           
  300.           The value of the Length part of an ASCII field entry includes the
  301.           null.   If padding  is necessary, the Length does not include the
  302.           pad byte.   Note  that there  is no  _count byte,_ as there is in
  303.           Pascal-type strings.   The Length part of the field takes care of
  304.           that.   The null  is not  strictly necessary, but may make things
  305.           slightly simpler for C programmers.
  306.           
  307.           The reader  should check  the type  to ensure  that it is what he
  308.           expects.   TIFF currently  allows more than 1 valid type for some
  309.           fields.   For example,  ImageWidth and ImageLength were specified
  310.           as having  type SHORT.  Very large images with more than 64K rows
  311.           or columns  are possible with some devices even now.  Rather than
  312.           add parallel  LONG tags  for these fields, it is cleaner to allow
  313.           both SHORT  and LONG  for ImageWidth  and similar  fields.    See
  314.           Appendix G for specific recommendations.
  315.           
  316.           Note that  there may  be more  than one IFD.  Each IFD is said to
  317.           define a _subfile._   One potential use of subsequent subfiles is
  318.           to describe  a _sub-image_   that  is somehow related to the main
  319.           image, such as a reduced resolution version of the image.
  320.           
  321.           If you have not already done so, you may wish to turn to Appendix
  322.           G to study the sample TIFF images.
  323.           
  324.           
  325.           2) Definitions
  326.           
  327.           Note that the TIFF structure as described in the previous section
  328.           is not  specific to  imaging applications in any way.  It is only
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.           TIFF 5.0                                          page 6
  340.           TIFF 5.0                                          page 6
  341.  
  342.  
  343.           the definitions of the fields themselves that jointly describe an
  344.           image.
  345.           
  346.           Before we  begin defining  the fields,  we will define some basic
  347.           concepts.   An image  is defined  to be  a rectangular  array  of
  348.           _pixels,_  each of which consists of one or more _samples._  With
  349.           monochromatic data,  we have  one sample  per pixel, and _sample_
  350.           and _pixel_   can  be  used  interchangeably.    RGB  color  data
  351.           contains three samples per pixel.
  352.           
  353.           
  354.           3) The Fields
  355.           
  356.           This section  describes the  fields defined  in this  version  of
  357.           TIFF.   More fields  may be  added in future versions_if possible
  358.           they will  be added in such a way so as not to break old software
  359.           that encounters a newer TIFF file.
  360.           
  361.           The documentation  for each  field contains the name of the field
  362.           (quite arbitrary, but convenient), the Tag value, the field Type,
  363.           the Number of Values (N) expected, comments describing the field,
  364.           and the  default, if  any.  Readers must assume the default value
  365.           if the field does not exist.
  366.           
  367.           _No default_  does not  mean that  a TIFF  writer should  not pay
  368.           attention to  the tag.  It simply means that there is no default.
  369.           If the  writer has reason to believe that readers will care about
  370.           the value  of this  field, the writer should write the field with
  371.           the appropriate value.  TIFF readers can do whatever they want if
  372.           they encounter a missing _no default_ field that they care about,
  373.           short of  refusing to  import the file.  For example, if a writer
  374.           does  not  write  out  a  PhotometricInterpretation  field,  some
  375.           applications will  interpret the  image _correctly,_  and  others
  376.           will display  the image  inverted.  This is not a good situation,
  377.           and writers should be careful not to let it happen.
  378.           
  379.           The  fields   are  grouped   into  several  categories:    basic,
  380.           informational, facsimile,  document storage and retrieval, and no
  381.           longer recommended.   A  future version  of the specification may
  382.           pull some of these categories into separate companion documents.
  383.           
  384.           Many fields  are described  in this  document, but  most are  not
  385.           _required._   See Appendix  G for  a list  of required fields, as
  386.           well as  examples of  how to combine fields into valid and useful
  387.           TIFF files.
  388.           Basic Fields
  389.           
  390.           
  391.           Basic fields  are  fields  that  are  fundamental  to  the  pixel
  392.           architecture or visual characteristics of an image.
  393.           
  394.           BitsPerSample
  395.           Tag  = 258  (102)
  396.           Type = SHORT
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.           TIFF 5.0                                          page 7
  407.           TIFF 5.0                                          page 7
  408.  
  409.  
  410.           N    = SamplesPerPixel
  411.           
  412.           Number of bits per sample.  Note that this tag allows a different
  413.           number of  bits per  sample for  each sample  corresponding to  a
  414.           pixel.   For example, RGB color data could use a different number
  415.           of bits  per sample for each of the three color planes.  Most RGB
  416.           files will have the same number of BitsPerSample for each sample.
  417.           Even in this case, be sure to include all three entries.  Writing
  418.           _8_ when you mean _8,8,8_ sets a bad precedent for other fields.
  419.           
  420.           Default = 1.  See also SamplesPerPixel.
  421.           
  422.           
  423.           ColorMap
  424.           Tag  = 320 (140)
  425.           Type = SHORT
  426.           N    = 3 * (2**BitsPerSample)
  427.           
  428.           This tag  defines a  Red-Green-Blue color  map for  palette color
  429.           images.   The palette color pixel value is used to index into all
  430.           3 subcurves.   For  example, a Palette color pixel having a value
  431.           of 0  would be  displayed according  to the 0th entry of the Red,
  432.           Green, and Blue subcurves.
  433.           
  434.           The subcurves  are stored  sequentially.   The Red  entries  come
  435.           first, followed  by the  Green  entries,  followed  by  the  Blue
  436.           entries.   The length  of each  subcurve is  2**BitsPerSample.  A
  437.           ColorMap entry  for an  8-bit Palette color image would therefore
  438.           have 3  * 256  entries.   The width  of each entry is 16 bits, as
  439.           implied  by  the  type  of  SHORT.    0  represents  the  minimum
  440.           intensity, and  65535 represents the maximum intensity.  Black is
  441.           represented by  0,0,0, and  white by  65535, 65535,  65535.   The
  442.           purpose of  the color  map is to act as a _lookup_  table mapping
  443.           pixel values from 0 to 2**BitsPerSample-1 into RGB triplets.
  444.           
  445.           The ColorResponseCurves  field may  be used  in conjunction  with
  446.           ColorMap to further refine the meaning of the RGB triplets in the
  447.           ColorMap.   However, the  ColorResponseCurves default  should  be
  448.           sufficient in most cases.
  449.           
  450.           See also PhotometricInterpretation_palette color.
  451.           
  452.           No default.   ColorMap  must be  included in  all  palette  color
  453.           images.
  454.           
  455.           
  456.           ColorResponseCurves
  457.           Tag  = 301 (12D)
  458.           Type = SHORT
  459.           N    = 3 * (2**BitsPerSample)
  460.           
  461.           This tag  defines three  color response curves, one each for Red,
  462.           Green and  Blue color  information.   The Red entries come first,
  463.           followed by the Green entries, followed by the Blue entries.  The
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.           TIFF 5.0                                          page 8
  474.           TIFF 5.0                                          page 8
  475.  
  476.  
  477.           length  of   each  subcurve   is  2**BitsPerSample,   using   the
  478.           BitsPerSample value corresponding to the respective primary.  The
  479.           width of  each entry is 16 bits, as implied by the type of SHORT.
  480.           0 represents  the minimum  intensity, and  65535  represents  the
  481.           maximum intensity.   Black  is represented by 0,0,0, and white by
  482.           65535, 65535,  65535.   Therefore, a ColorResponseCurve entry for
  483.           RGB data  where each of the samples is 8 bits deep would have 3 *
  484.           256 entries, each consisting of a SHORT.
  485.           
  486.           The purpose of the color response curves is to refine the content
  487.           of RGB color images.
  488.           
  489.           See Appendix H, section VII, for further information.
  490.           
  491.           Default:  curves based on the NTSC recommended gamma of 2.2.
  492.           
  493.           
  494.           Compression
  495.           Tag  = 259  (103)
  496.           Type = SHORT
  497.           N    = 1
  498.           
  499.           1 =  No compression,  but pack  data into  bytes  as  tightly  as
  500.           possible, with  no unused  bits except  at the end of a row.  The
  501.           bytes are  stored as  an array of type BYTE, for BitsPerSample <=
  502.           8,  SHORT   if  BitsPerSample   >  8  and  <=  16,  and  LONG  if
  503.           BitsPerSample >  16 and <= 32.  The byte ordering of data >8 bits
  504.           must be  consistent with  that specified  in the TIFF file header
  505.           (bytes 0  and 1).   _II_    format  files  will  have  the  least
  506.           significant bytes  preceeding the  most significant  bytes  while
  507.           _MM_  format files will have the opposite.
  508.           
  509.                If the  number of  bits per  sample is not a power of 2, and
  510.           you are willing to give up some space for better performance, you
  511.           may wish to use the next higher power of 2.  For example, if your
  512.           data can  be represented  in 6 bits, you may wish to specify that
  513.           it is 8 bits deep.
  514.           
  515.                Rows are  required to  begin on byte boundaries.  The number
  516.           of bytes  per row  is therefore  (ImageWidth *  SamplesPerPixel *
  517.           BitsPerSample  +   7)  /  8,  assuming  integer  arithmetic,  for
  518.           PlanarConfiguration=1.     Bytes  per   row  is   (ImageWidth   *
  519.           BitsPerSample + 7) / 8 for PlanarConfiguration=2.
  520.           
  521.                Some graphics  systems want rows to be word- or double-word-
  522.           aligned.   Uncompressed TIFF  rows will  need to  be copied  into
  523.           word- or  double-word-padded row  buffers before  being passed to
  524.           the graphics routines in these environments.
  525.           
  526.           2 =  CCITT Group  3 1-Dimensional  Modified  Huffman  run  length
  527.           encoding.   See Appendix  B:   _Data Compression  --  Scheme  2._
  528.           BitsPerSample must  be 1,  since  this  type  of  compression  is
  529.           defined only for bilevel images.
  530.           
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.           TIFF 5.0                                          page 9
  541.           TIFF 5.0                                          page 9
  542.  
  543.  
  544.                When  you  decompress  data  that  has  been  compressed  by
  545.           Compression=2, you  must translate  white runs into 0_s and black
  546.           runs into  1_s.   Therefore, the normal PhotometricInterpretation
  547.           for those  compression types  is 0  (WhiteIsZero).   If a  reader
  548.           encounters a  PhotometricInterpretation of  1  (BlackIsZero)  for
  549.           such an  image, the  image should  be displayed  and printed with
  550.           black and white reversed.
  551.           
  552.           5 = LZW Compression,  for grayscale, mapped color, and full color
  553.           images.  See Appendix F.
  554.           
  555.           32773 =  PackBits compression,  a simple byte oriented run length
  556.           scheme for 1-bit images.  See Appendix C.
  557.           
  558.           Data compression only applies to raster image data, as pointed to
  559.           by StripOffsets.  All other TIFF information is unaffected.
  560.           
  561.           Default = 1.
  562.           
  563.           
  564.           GrayResponseCurve
  565.           Tag  = 291 (123)
  566.           Type = SHORT
  567.           N    = 2**BitsPerSample
  568.           
  569.           The purpose  of the  gray response curve and the gray units is to
  570.           provide more  exact photometric  interpretation  information  for
  571.           gray scale image data, in terms of optical density.
  572.           
  573.           The  GrayScaleResponseUnits   specifies  the   accuracy  of   the
  574.           information contained  in the  curve.   Since optical  density is
  575.           specified in  terms of  fractional numbers, this tag is necessary
  576.           to know  how to  interpret the  stored integer  information.  For
  577.           example, if  GrayScaleResponseUnits is  set to 4 (ten-thousandths
  578.           of a  unit), and a GrayScaleResponseCurve number for gray level 4
  579.           is 3455,  then the  resulting actual  value is  0.3455.   Optical
  580.           densitometers typically measure densities within the range of 0.0
  581.           to 2.0.
  582.           
  583.           If the  gray scale  response curve  is known  for the data in the
  584.           TIFF file, and if the gray scale response of the output device is
  585.           known, then  an intelligent  conversion can  be made  between the
  586.           input data and the output device.  For example, the output can be
  587.           made to  look just  like the  input.   In addition,  if the input
  588.           image lacks  contrast (as  can be  seen from the response curve),
  589.           then appropriate contrast enhancements can be made.
  590.           
  591.           The purpose  of the  gray scale  response curve  is to  act as  a
  592.           _lookup_   table mapping values from 0 to 2**BitsPerSample-1 into
  593.           specific   density    values.      The   0th   element   of   the
  594.           GrayResponseCurve array  is used to define the gray value for all
  595.           pixels  having   a  value   of  0,   the  1st   element  of   the
  596.           GrayResponseCurve array  is used to define the gray value for all
  597.           pixels having  a value of 1, and so on, up to 2**BitsPerSample-1.
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604.  
  605.  
  606.  
  607.           TIFF 5.0                                          page 10
  608.           TIFF 5.0                                          page 10
  609.  
  610.  
  611.           If your  data is  _really,_ say, 7-bit data, but you are adding a
  612.           1-bit pad  to each  pixel to  turn it into 8-bit data, everything
  613.           still works:   If  the data is high-order justified, half of your
  614.           GrayResponseCurve entries  (the odd ones, probably) will never be
  615.           used, but  that doesn_t  hurt anything.  If the data is low-order
  616.           justified, your  pixel values  will be between 0 and 127, so make
  617.           your GrayResponseCurve  accordingly.   What your  curve does from
  618.           128 to  255 doesnÆt matter.  Note that low-order justification is
  619.           probably not  a good  idea, however,  since not  all applications
  620.           look at GrayResponseCurve.  Note also that LZW compression yields
  621.           the same  compression ratio  regardless of  whether the  data  is
  622.           high-order or low-order justified.
  623.           
  624.           It is  permissable to  have a  GrayResponseCurve even for bilevel
  625.           (1-bit) images.   The  GrayResponseCurve will  have 2 values.  It
  626.           should be noted, however, that TIFF B readers are not required to
  627.           pay attention  to  GrayResponseCurves  in  TIFF  B  files.    See
  628.           Appendix G.
  629.           
  630.           If both  GrayResponseCurve and  PhotometricInterpretation  fields
  631.           exist  in   the  IFD,   GrayResponseCurve  values   override  the
  632.           PhotometricInterpretation value.   But it is a good idea to write
  633.           out both, since some applications do not yet pay attention to the
  634.           GrayResponseCurve.
  635.           
  636.           Writers may  wish to  purchase a  Kodak Reflection Density Guide,
  637.           catalog number  146 5947,  available for  $10 or  so at  prepress
  638.           supply houses,  to help them figure out reasonable density values
  639.           for their scanner or frame grabber.  If that sounds like too much
  640.           work,   we    recommend   a    curve   that    is    linear    in
  641.           intensity/reflectance.  To compute reflectance from density:  R =
  642.           1 /  pow(10,D).   To compute  density from reflectance: D = log10
  643.           (1/R).   A typical  4-bit GrayResponseCurve  may  look  therefore
  644.           something like:   2000,  1177, 875, 699, 574, 477, 398, 331, 273,
  645.           222, 176,  135, 97, 62, 30, 0, assuming GrayResponseUnit=3.  Such
  646.           a curve would be consistent with PhotometricInterpretation=1.
  647.           
  648.           See also GrayResponseUnit, PhotometricInterpretation, ColorMap.
  649.           
  650.           
  651.           GrayResponseUnit
  652.           Tag  = 290 (122)
  653.           Type = SHORT
  654.           N    = 1
  655.           
  656.           1 = Number represents tenths of a unit.
  657.           2 = Number represents hundredths of a unit.
  658.           3 = Number represents thousandths of a unit.
  659.           4 = Number represents ten-thousandths of a unit.
  660.           5 = Number represents hundred-thousandths of a unit.
  661.           
  662.           Modifies GrayResponseCurve.
  663.           
  664.           See also GrayResponseCurve.
  665.  
  666.  
  667.  
  668.  
  669.  
  670.  
  671.  
  672.  
  673.  
  674.           TIFF 5.0                                          page 11
  675.           TIFF 5.0                                          page 11
  676.  
  677.  
  678.           
  679.           For historical  reasons, the  default is 2.  However, for greater
  680.           accuracy, we recommend using 3.
  681.           
  682.           
  683.           ImageLength
  684.           Tag  = 257  (101)
  685.           Type = SHORT or LONG
  686.           N    = 1
  687.           
  688.           The image_s  length (height) in pixels (Y: vertical).  The number
  689.           of rows  (sometimes described as _scan lines") in the image.  See
  690.           also ImageWidth.
  691.           
  692.           No default.
  693.           
  694.           
  695.           ImageWidth
  696.           Tag  = 256  (100)
  697.           Type = SHORT or LONG
  698.           N    = 1
  699.           
  700.           The image_s  width, in  pixels (X:  horizontal).   The number  of
  701.           columns in the image.  See also ImageLength.
  702.           
  703.           No default.
  704.           
  705.           
  706.           NewSubfileType
  707.           Tag =  254  (FE)
  708.           Type = LONG
  709.           N = 1
  710.           
  711.           Replaces the  old SubfileType  field, due  to limitations  in the
  712.           definition of that field.
  713.           
  714.           A general  indication of  the kind  of data  that is contained in
  715.           this subfile.   This  field is  made up of a set of 32 flag bits.
  716.           Unused bits are expected to be 0.  Bit 0 is the low-order bit.
  717.           
  718.           Currently defined values are:
  719.           
  720.           Bit 0     is 1  if the  image is  a reduced resolution version of
  721.           another image in this TIFF file; else the bit is 0.
  722.           Bit 1     is 1  if the  image is  a single  page of  a multi-page
  723.           image (see the PageNumber tag description); else the bit is 0.
  724.           Bit 2     is 1  if the  image defines  a  transparency  mask  for
  725.           another image  in this  TIFF file.  The PhotometricInterpretation
  726.           value must be 4, designating a transparency mask.
  727.           
  728.           These values  have been  defined as  bit flags  because they  are
  729.           pretty much independent of each other.  For example, it be useful
  730.           to have  four images  in a  single TIFF  file: a  full resolution
  731.           image, a  reduced resolution  image, a  transparency mask for the
  732.  
  733.  
  734.  
  735.  
  736.  
  737.  
  738.  
  739.  
  740.  
  741.           TIFF 5.0                                          page 12
  742.           TIFF 5.0                                          page 12
  743.  
  744.  
  745.           full resolution  image, and  a transparency  mask for the reduced
  746.           resolution image.  Each of the four images would have a different
  747.           value for the NewSubfileType field.
  748.           
  749.           Default is 0.
  750.           
  751.           
  752.           PhotometricInterpretation
  753.           Tag  = 262  (106)
  754.           Type = SHORT
  755.           N    = 1
  756.           
  757.           0 =  For bilevel  and grayscale  images:   0 is  imaged as white.
  758.           2**BitsPerSample-1 is  imaged as  black.    If  GrayResponseCurve
  759.           exists,  it   overrides  the   PhotometricInterpretation   value,
  760.           although  it  is  safer  to  make  them  match,  since  some  old
  761.           applications may still be ignoring GrayResponseCurve. This is the
  762.           normal value for Compression=2.
  763.           
  764.           1 =  For bilevel  and grayscale  images:   0 is  imaged as black.
  765.           2**BitsPerSample-1  is  imaged  as  white.  If  GrayResponseCurve
  766.           exists,  it   overrides  the   PhotometricInterpretation   value,
  767.           although  it  is  safer  to  make  them  match,  since  some  old
  768.           applications may  still be  ignoring GrayResponseCurve.  If  this
  769.           value is  specified for  Compression=2, the  image should display
  770.           and print reversed.
  771.           
  772.           2 = RGB.  In the RGB model, a color is described as a combination
  773.           of the  three primary  colors of  light (red, green, and blue) in
  774.           particular concentrations.   For  each of  the three  samples,  0
  775.           represents minimum intensity, and 2**BitsPerSample - 1 represents
  776.           maximum intensity.   Thus  an RGB  value  of  (0,0,0)  represents
  777.           black,  and   (255,255,255)  represents   white,  assuming  8-bit
  778.           samples.   For PlanarConfiguration = 1, the samples are stored in
  779.           the indicated  order:   first Red,  then Green,  then Blue.   For
  780.           PlanarConfiguration =  2, the  StripOffsets for the sample planes
  781.           are stored  in the  indicated order:   first the Red sample plane
  782.           StripOffsets, then  the Green  plane StripOffsets,  then the Blue
  783.           plane StripOffsets.
  784.           
  785.                The ColorResponseCurves field may be used to globally refine
  786.           or alter  the color  balance of  an RGB  image without  having to
  787.           change the values of the pixels themselves.
  788.           
  789.           3="Palette color._     In this  mode, a color is described with a
  790.           single sample.   The  sample is  used as  an index into ColorMap.
  791.           The sample  is used to index into each of the red, green and blue
  792.           curve tables to retrieve an RGB triplet defining an actual color.
  793.           When this  PhotometricInterpretation value  is  used,  the  color
  794.           response curves  must also  be supplied.  SamplesPerPixel must be
  795.           1.
  796.           
  797.           4 =  Transparency Mask.   This  means that  the image  is used to
  798.           define an  irregularly shaped region of another image in the same
  799.  
  800.  
  801.  
  802.  
  803.  
  804.  
  805.  
  806.  
  807.  
  808.           TIFF 5.0                                          page 13
  809.           TIFF 5.0                                          page 13
  810.  
  811.  
  812.           TIFF  file.     SamplesPerPixel  and  BitsPerSample  must  be  1.
  813.           PackBits compression  is recommended.    The  1-bits  define  the
  814.           interior of  the region;  the 0-bits  define the  exterior of the
  815.           region.  The Transparency Mask must have the same ImageLength and
  816.           ImageWidth as the main image.
  817.           
  818.                A reader  application can  use the  mask to  determine which
  819.           parts of the image to display.  Main image pixels that correspond
  820.           to 1-bits  in the  transparency mask  are imaged to the screen or
  821.           printer, but  main image  pixels that correspond to 0-bits in the
  822.           mask are not displayed or printed.
  823.           
  824.                It is  possible to  generalize the  notion of a transparency
  825.           mask to  include partial  transparency, but  it is not clear that
  826.           such information would be useful to a desktop publishing program.
  827.           
  828.           No default.   That  means that  if you  care  if  your  image  is
  829.           displayed and  printed as  _normal_ vs _inverted,_ you must write
  830.           out this  field.   Do not rely on applications defaulting to what
  831.           you want!   PhotometricInterpretation  =  1  is  recommended  for
  832.           bilevel (except  for Compression=2)  and grayscale images, due to
  833.           popular user  interfaces for changing the brightness and contrast
  834.           of images.
  835.           
  836.           
  837.           PlanarConfiguration
  838.           Tag  = 284  (11C)
  839.           Type = SHORT
  840.           N    = 1
  841.           
  842.           1 =  The sample values for each pixel are stored contiguously, so
  843.           that   there    is   a    single   image    plane.            See
  844.           PhotometricInterpretation to  determine the  order of the samples
  845.           within the  pixel data.   So,  for RGB  data, the  data is stored
  846.           RGBRGBRGB...and so on.
  847.           
  848.           2 =  The samples  are stored  in separate  _sample planes._   The
  849.           values in StripOffsets and StripByteCounts are then arranged as a
  850.           2-dimensional array, with SamplesPerPixel rows and StripsPerImage
  851.           columns.      (All of  the columns  for row  0 are  stored first,
  852.           followed   by    the   columns    of   row   1,   and   so   on.)
  853.           PhotometricInterpretation describes  the type  of  data  that  is
  854.           stored in  each sample  plane.   For example,  RGB data is stored
  855.           with the  Red samples  in one sample plane, the Green in another,
  856.           and the Blue in another.
  857.           
  858.           If SamplesPerPixel  is 1,  PlanarConfiguration is irrelevant, and
  859.           should not be included.
  860.           Default is 1.  See also BitsPerSample, SamplesPerPixel.
  861.           
  862.           
  863.           Predictor
  864.           Tag  = 317 (13D)
  865.           Type = SHORT
  866.  
  867.  
  868.  
  869.  
  870.  
  871.  
  872.  
  873.  
  874.  
  875.           TIFF 5.0                                          page 14
  876.           TIFF 5.0                                          page 14
  877.  
  878.  
  879.           N    = 1
  880.           
  881.           To be used when Compression=5 (LZW).  See Appendix F.
  882.           
  883.           1 = No prediction scheme used before coding.
  884.           
  885.           Default is 1.
  886.           
  887.           
  888.           ResolutionUnit
  889.           Tag  = 296 (128)
  890.           Type = SHORT
  891.           N    = 1
  892.           
  893.           To be used with XResolution and YResolution.
  894.           
  895.           1 =  No absolute  unit of  measurement.  Used for images that may
  896.           have a  non-square  aspect  ratio,  but  no  meaningful  absolute
  897.           dimensions.   The drawback  of ResolutionUnit=1 is that different
  898.           applications will  import the  image at different sizes.  Even if
  899.           the decision  is quite  arbitrary, it might be better to use dots
  900.           per inch  or  dots  per  centimeter,  and  pick  XResolution  and
  901.           YResolution such that the aspect ratio is correct and the maximum
  902.           dimension of  the image is about four inches (the _four_ is quite
  903.           arbitrary.)
  904.           2 = Inch.
  905.           3 = Centimeter.
  906.           
  907.           Default is 2.  See also XResolution, YResolution.
  908.           
  909.           
  910.           RowsPerStrip
  911.           Tag  = 278  (116)
  912.           Type = SHORT or LONG
  913.           N    = 1
  914.           
  915.           The number  of rows  per strip.  The image data is organized into
  916.           strips for  fast access  to individual  rows  when  the  data  is
  917.           compressed_though this  field is  valid even  if the  data is not
  918.           compressed.
  919.           
  920.           RowsPerStrip and  ImageLength together  tell  us  the  number  of
  921.           strips in  the entire  image.   The equation  is StripsPerImage =
  922.           (ImageLength + RowsPerStrip - 1) / RowsPerStrip, assuming integer
  923.           arithmetic.
  924.           
  925.           Note that  either SHORT  or LONG  values can  be used  to specify
  926.           RowsPerStrip.   SHORT values  may be  used for  small TIFF files.
  927.           It should  be noted,  however, that  earlier  TIFF  specification
  928.           revisions required  LONG values  and that  some software  may not
  929.           expect SHORT values.  See Appendix G for further recommendations.
  930.           
  931.           Default is  2**32 -  1, which  is effectively infinity.  That is,
  932.           the entire  image is  one strip.   We  do not  recommend a single
  933.  
  934.  
  935.  
  936.  
  937.  
  938.  
  939.  
  940.  
  941.  
  942.           TIFF 5.0                                          page 15
  943.           TIFF 5.0                                          page 15
  944.  
  945.  
  946.           strip, however.   Choose  RowsPerStrip such  that each  strip  is
  947.           about 8K  bytes, even  if the  data is  not compressed,  since it
  948.           makes buffering  simpler for  readers.   The _8K_  part is pretty
  949.           arbitrary, but seems to work well.
  950.           
  951.           See also ImageLength, StripOffsets, StripByteCounts.
  952.           
  953.           
  954.           SamplesPerPixel
  955.           Tag  = 277  (115)
  956.           Type = SHORT
  957.           N    = 1
  958.           
  959.           The number  of samples  per pixel.    SamplesPerPixel  is  1  for
  960.           bilevel, grayscale, and palette color images.  SamplesPerPixel is
  961.           3 for RGB images.
  962.           
  963.           Default = 1.  See also BitsPerSample, PhotometricInterpretation.
  964.           
  965.           
  966.           StripByteCounts
  967.           Tag  = 279  (117)
  968.           Type = SHORT or LONG
  969.           N    = StripsPerImage for PlanarConfiguration equal to 1.
  970.                = SamplesPerPixel  * StripsPerImage  for PlanarConfiguration
  971.           equal to 2
  972.           
  973.           For each strip, the number of bytes in that strip.  The existence
  974.           of  this   field  greatly   simplifies  the  chore  of  buffering
  975.           compressed data, if the strip size is reasonable.
  976.           
  977.           No default.  See also StripOffsets, RowsPerStrip.
  978.           
  979.           
  980.           StripOffsets
  981.           Tag  = 273  (111)
  982.           Type = SHORT or LONG
  983.           N    = StripsPerImage for PlanarConfiguration equal to 1.
  984.                = SamplesPerPixel  * StripsPerImage  for PlanarConfiguration
  985.           equal to 2
  986.           
  987.           For each  strip, the  byte offset  of that  strip.  The offset is
  988.           specified with  respect to  the beginning of the TIFF file.  Note
  989.           that this  implies that  each strip has a location independent of
  990.           the locations  of other  strips.   This feature may be useful for
  991.           editing applications.  This field is the only way for a reader to
  992.           find the image data, and hence must exist.
  993.           
  994.           Note that  either SHORT or LONG values can be used to specify the
  995.           strip offsets.   SHORT  values  may be used for small TIFF files.
  996.           It should  be noted,  however, that  earlier TIFF  specifications
  997.           required LONG strip offsets and that some software may not expect
  998.           SHORT values.  See Appendix G for further recommendations.
  999.           
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.           TIFF 5.0                                          page 16
  1010.           TIFF 5.0                                          page 16
  1011.  
  1012.  
  1013.           No default.  See also StripByteCounts, RowsPerStrip.
  1014.           
  1015.           
  1016.           XResolution
  1017.           Tag  = 282  (11A)
  1018.           Type = RATIONAL
  1019.           N    = 1
  1020.           
  1021.           The number of pixels per ResolutionUnit in the X direction, i.e.,
  1022.           in the  ImageWidth direction.   It  is, of  course, not mandatory
  1023.           that the  image be  actually printed  at the size implied by this
  1024.           parameter.   It is  up to the application to use this information
  1025.           as it wishes.
  1026.           
  1027.           No default.  See also YResolution, ResolutionUnit.
  1028.           
  1029.           
  1030.           YResolution
  1031.           Tag  = 283  (11B)
  1032.           Type = RATIONAL
  1033.           N    = 1
  1034.           
  1035.           The number of pixels per ResolutionUnit in the Y direction, i.e.,
  1036.           in the ImageLength direction.
  1037.           
  1038.           No default.  See also XResolution, ResolutionUnit.
  1039.           
  1040.           
  1041.           Informational Fields
  1042.           
  1043.           
  1044.           Informational  fields   are  fields   that  can   provide  useful
  1045.           information to  a user,  such as where the image came from.  Most
  1046.           are ASCII  fields.   An application could have some sort of _More
  1047.           Info..._ dialog box to display such information.
  1048.           
  1049.           Artist
  1050.           Tag  = 315  (13B)
  1051.           Type = ASCII
  1052.           
  1053.           Person who created the image.
  1054.           
  1055.           If you need to attach a Copyright notice to an image, this is the
  1056.           place to  do it.  In fact, you may wish to write out the contents
  1057.           of the field immediately after the 8-byte TIFF header.  Just make
  1058.           sure your  IFD and field pointers are set accordingly, and you_re
  1059.           all set.
  1060.           
  1061.           
  1062.           DateTime
  1063.           Tag  = 306  (132)
  1064.           Type = ASCII
  1065.           N    = 20
  1066.           
  1067.  
  1068.  
  1069.  
  1070.  
  1071.  
  1072.  
  1073.  
  1074.  
  1075.  
  1076.           TIFF 5.0                                          page 17
  1077.           TIFF 5.0                                          page 17
  1078.  
  1079.  
  1080.           Date and  time of  image creation.   Use  the format  _YYYY:MM:DD
  1081.           HH:MM:SS_, with hours on a 24-hour clock, and one space character
  1082.           between the  date and  the time.    The  length  of  the  string,
  1083.           including the null, is 20 bytes.
  1084.           
  1085.           
  1086.           HostComputer
  1087.           Tag  = 316  (13C)
  1088.           Type = ASCII
  1089.           
  1090.           _ENIAC_, or whatever.
  1091.           
  1092.           See also Make, Model, Software.
  1093.           
  1094.           
  1095.           ImageDescription
  1096.           Tag  = 270 (10E)
  1097.           Type = ASCII
  1098.           
  1099.           For example,  a user  may wish  to attach a comment such as _1988
  1100.           company picnic_ to an image.
  1101.           
  1102.           It has  been suggested  that  this  is  what  the  newspaper  and
  1103.           magazine industry calls a _slug._
  1104.           
  1105.           
  1106.           Make
  1107.           Tag  = 271  (10F)
  1108.           Type = ASCII
  1109.           
  1110.           Manufacturer of the scanner, video digitizer, or whatever.
  1111.           
  1112.           See also Model, Software.
  1113.           
  1114.           
  1115.           Model
  1116.           Tag  = 272  (110)
  1117.           Type = ASCII
  1118.           
  1119.           The  model  name/number  of  the  scanner,  video  digitizer,  or
  1120.           whatever.
  1121.           
  1122.           This tag is intended for user information only.
  1123.           
  1124.           See also Make, Software.
  1125.           
  1126.           
  1127.           Software
  1128.           Tag  = 305  (131)
  1129.           Type = ASCII
  1130.           
  1131.           Name and  release number of the software package that created the
  1132.           image.
  1133.           
  1134.  
  1135.  
  1136.  
  1137.  
  1138.  
  1139.  
  1140.  
  1141.  
  1142.  
  1143.           TIFF 5.0                                          page 18
  1144.           TIFF 5.0                                          page 18
  1145.  
  1146.  
  1147.           This tag is intended for user information only.
  1148.           
  1149.           See also Make, Model.
  1150.           
  1151.           
  1152.           Facsimile Fields
  1153.           
  1154.           
  1155.           Facsimile fields  may be  useful if  you are  using TIFF to store
  1156.           facsimile messages  in _raw_  form.  They are not recommended for
  1157.           use in interchange with desktop publishing applications.
  1158.           
  1159.           Compression (a basic tag)
  1160.           Tag  = 259  (103)
  1161.           Type = SHORT
  1162.           N    = 1
  1163.           
  1164.           3 =  Facsimile-compatible CCITT  Group 3, exactly as specified in
  1165.           _Standardization of  Group 3  facsimile  apparatus  for  document
  1166.           transmission,_   Recommendation T.4,  Volume VII, Fascicle VII.3,
  1167.           Terminal Equipment  and Protocols  for  Telematic  Services,  The
  1168.           International  Telegraph  and  Telephone  Consultative  Committee
  1169.           (CCITT), Geneva,  1985, pages  16 through  31.   Each strip  must
  1170.           begin on  a byte  boundary.   (But recall  that an image can be a
  1171.           single strip.)   Rows  that are  not the first row of a strip are
  1172.           not required  to begin on a byte boundary.  The data is stored as
  1173.           bytes,  not   words_byte-reversal  is   not  allowed.    See  the
  1174.           Group3Options field for Group 3 options such as 1D vs 2D coding.
  1175.           
  1176.           4 =  Facsimile-compatible CCITT  Group 4, exactly as specified in
  1177.           _Facsimile Coding  Schemes and Coding Control Functions for Group
  1178.           4 Facsimile Apparatus,_  Recommendation T.6, Volume VII, Fascicle
  1179.           VII.3, Terminal  Equipment and  Protocols for Telematic Services,
  1180.           The International  Telegraph and Telephone Consultative Committee
  1181.           (CCITT), Geneva,  1985, pages  40 through  48.   Each strip  must
  1182.           begin on  a byte  boundary.  Rows that are not the first row of a
  1183.           strip are  not required to begin on a byte boundary.  The data is
  1184.           stored as  bytes, not  words.   See the  Group4Options field  for
  1185.           Group 4 options.
  1186.           
  1187.           
  1188.           Group3Options
  1189.           Tag  = 292  (124)
  1190.           Type = LONG
  1191.           N    = 1
  1192.           
  1193.           See Compression=3.   This  field is  made up  of a set of 32 flag
  1194.           bits.   Unused bits are expected to be 0.  Bit 0 is the low-order
  1195.           bit.   It is probably not safe to try to read the file if any bit
  1196.           of this field is set that you don_t know the meaning of.
  1197.           
  1198.           Bit 0     is 1  for 2-dimensional  coding (else  1-dimensional is
  1199.           assumed).   For 2-D  coding, if more than one strip is specified,
  1200.           each strip  must begin  with a  1-dimensionally coded line.  That
  1201.  
  1202.  
  1203.  
  1204.  
  1205.  
  1206.  
  1207.  
  1208.  
  1209.  
  1210.           TIFF 5.0                                          page 19
  1211.           TIFF 5.0                                          page 19
  1212.  
  1213.  
  1214.           is, RowsPerStrip  should be  a multiple  of  _Parameter  K_    as
  1215.           documented in the CCITT specification.
  1216.           
  1217.           Bit 1     is 1 if uncompressed mode is used.
  1218.           
  1219.           Bit 2     is 1  if fill  bits have been added as necessary before
  1220.           EOL codes  such that  EOL always  ends on  a byte  boundary, thus
  1221.           ensuring an  eol-sequence of  a 1 byte preceded by a zero nibble:
  1222.           xxxx-0000 0000-0001.
  1223.           
  1224.           Default  is   0,  for  basic  1-dimensional  coding.    See  also
  1225.           Compression.
  1226.           
  1227.           
  1228.           Group4Options
  1229.           Tag  =  293  (125)
  1230.           Type = LONG
  1231.           N    = 1
  1232.           
  1233.           See Compression=4.   This  field is  made up  of a set of 32 flag
  1234.           bits.   Unused bits are expected to be 0.  Bit 0 is the low-order
  1235.           bit.   It is probably not safe to try to read the file if any bit
  1236.           of this  field is  set that  you don_t know the meaning of.  Gray
  1237.           scale and color coding schemes are under study, and will be added
  1238.           when finalized.
  1239.           
  1240.           For 2-D  coding, each  strip is  encoded as if it were a separate
  1241.           image.   In particular, each strip begins on a byte boundary; and
  1242.           the coding  for the first row of a strip is encoded independently
  1243.           of the  previous row,  using horizontal codes, as if the previous
  1244.           row is  entirely white.   Each strip ends with the 24-bit end-of-
  1245.           facsimile block (EOFB).
  1246.           
  1247.           Bit 0     is unused.
  1248.           Bit 1     is 1 if uncompressed mode is used.
  1249.           
  1250.           Default is  0, for  basic 2-dimensional  binary compression.  See
  1251.           also Compression.
  1252.           
  1253.           
  1254.           Document Storage and Retrieval Fields
  1255.           
  1256.           
  1257.           These fields  may be  useful for  document storage  and retrieval
  1258.           applications.   They are  not recommended  for use in interchange
  1259.           with desktop publishing applications.
  1260.           
  1261.           DocumentName
  1262.           Tag  = 269  (10D)
  1263.           Type = ASCII
  1264.           
  1265.           The name of the document from which this image was scanned.
  1266.           
  1267.           See also PageName.
  1268.  
  1269.  
  1270.  
  1271.  
  1272.  
  1273.  
  1274.  
  1275.  
  1276.  
  1277.           TIFF 5.0                                          page 20
  1278.           TIFF 5.0                                          page 20
  1279.  
  1280.  
  1281.           
  1282.           
  1283.           PageName
  1284.           Tag  = 285  (11D)
  1285.           Type = ASCII
  1286.           
  1287.           The name of the page from which this image was scanned.
  1288.           
  1289.           See also DocumentName.
  1290.           
  1291.           No default.
  1292.           
  1293.           PageNumber
  1294.           Tag  = 297  (129)
  1295.           Type = SHORT
  1296.           N    = 2
  1297.           
  1298.           This tag is used to specify page numbers of a multiple page (e.g.
  1299.           facsimile) document.   Two SHORT values are specified.  The first
  1300.           value is the page number; the second value is the total number of
  1301.           pages in the document.
  1302.           
  1303.           Note that  pages need  not appear  in numerical order.  The first
  1304.           page is 0 (zero).
  1305.           
  1306.           No default.
  1307.           
  1308.           
  1309.           XPosition
  1310.           Tag  = 286  (11E)
  1311.           Type = RATIONAL
  1312.           
  1313.           The X  offset of  the left side of the image, with respect to the
  1314.           left side of the page, in ResolutionUnits.
  1315.           
  1316.           No default.  See also YPosition.
  1317.           
  1318.           
  1319.           YPosition
  1320.           Tag  = 287  (11F)
  1321.           Type = RATIONAL
  1322.           
  1323.           The Y  offset of the top of the image, with respect to the top of
  1324.           the page, in ResolutionUnits.  In the TIFF coordinate scheme, the
  1325.           positive Y  direction  is  down,  so  that  YPosition  is  always
  1326.           positive.
  1327.           
  1328.           No default.  See also XPosition.
  1329.           
  1330.           
  1331.           No Longer Recommended
  1332.           
  1333.           
  1334.  
  1335.  
  1336.  
  1337.  
  1338.  
  1339.  
  1340.  
  1341.  
  1342.  
  1343.  
  1344.           TIFF 5.0                                          page 21
  1345.           TIFF 5.0                                          page 21
  1346.  
  1347.  
  1348.           These fields  are not  recommended except  perhaps for local use.
  1349.           They should  not be used for image interchange.  They have either
  1350.           been superseded  by other fields, have been found to have serious
  1351.           drawbacks, or are simply not as useful as once thought.  They may
  1352.           be dropped entirely from a future revision of the specification.
  1353.           
  1354.           CellLength
  1355.           Tag  = 265  (109)
  1356.           Type = SHORT
  1357.           N    = 1
  1358.           
  1359.           The length, in 1-bit samples, of the dithering/halftoning matrix.
  1360.           Assumes that Threshholding = 2.
  1361.           
  1362.           This field,  plus CellWidth  and Threshholding,  are  problematic
  1363.           because they  cannot safely be used to reverse-engineer grayscale
  1364.           image data  out of dithered/halftoned black-and-white data, which
  1365.           is their  only plausible  purpose.  The only _right_ way to do it
  1366.           is to  not bother  with anything  like these  fields, and instead
  1367.           write  some  sophisticated  pattern-matching  software  that  can
  1368.           handle screen  angles that  are not  multiples of 45 degrees, and
  1369.           other such challenging dithered/halftoned data.
  1370.           
  1371.           So we  do not  recommend trying  to convert dithered or halftoned
  1372.           data into  grayscale data.   Dithered  and halftoned data require
  1373.           careful treatment  to avoid  _stretch marks,_ but it can be done.
  1374.           If you  want grayscale images, get them directly from the scanner
  1375.           or frame grabber or whatever.
  1376.           
  1377.           No default.  See also Threshholding.
  1378.           
  1379.           
  1380.           CellWidth
  1381.           Tag  = 264  (108)
  1382.           Type = SHORT
  1383.           N    = 1
  1384.           
  1385.           The width, in 1-bit samples, of the dithering/halftoning matrix.
  1386.           
  1387.           No default.   See  also Threshholding.    See  the  comments  for
  1388.           CellLength.
  1389.           
  1390.           
  1391.           FillOrder
  1392.           Tag  = 266  (10A)
  1393.           Type = SHORT
  1394.           N    = 1
  1395.           
  1396.           The order of data values within a byte.
  1397.           1 = most significant bits of the byte are filled first.  That is,
  1398.           data values  (or code  words) are  ordered from high order bit to
  1399.           low order bit within a byte.
  1400.           2 =  least significant  bits are  filled  first.    Since  little
  1401.           interest has  been expressed  in least-significant  fill order to
  1402.  
  1403.  
  1404.  
  1405.  
  1406.  
  1407.  
  1408.  
  1409.  
  1410.  
  1411.           TIFF 5.0                                          page 22
  1412.           TIFF 5.0                                          page 22
  1413.  
  1414.  
  1415.           date, and since it is easy and inexpensive for writers to reverse
  1416.           bit order (use a 256-byte lookup table), we recommend FillOrder=2
  1417.           for private (non-interchange) use only.
  1418.           
  1419.           Default is FillOrder = 1.
  1420.           
  1421.           
  1422.           FreeByteCounts
  1423.           Tag  = 289  (121)
  1424.           Type = LONG
  1425.           
  1426.           For each  _free block_   in  the file, the number of bytes in the
  1427.           block.
  1428.           
  1429.           TIFF  readers   can  ignore  FreeOffsets  and  FreeByteCounts  if
  1430.           present.
  1431.           
  1432.           FreeOffsets and  FreeByteCounts do  not constitute a remapping of
  1433.           the logical address space of the file.
  1434.           
  1435.           Since this  information can  be generated  by scanning  the IFDs,
  1436.           StripOffsets, and StripByteCounts, FreeByteCounts and FreeOffsets
  1437.           are not needed.
  1438.           
  1439.           In addition, it is not clear what should happen if FreeByteCounts
  1440.           and FreeOffsets exist in more than one IFD.
  1441.           
  1442.           See also FreeOffsets.
  1443.           
  1444.           
  1445.           FreeOffsets
  1446.           Tag  = 288  (120)
  1447.           Type = LONG
  1448.           
  1449.           For each _free block_  in the file, its byte offset.
  1450.           
  1451.           See also FreeByteCounts.
  1452.           
  1453.           
  1454.           MaxSampleValue
  1455.           Tag  = 281  (119)
  1456.           Type = SHORT
  1457.           N    = SamplesPerPixel
  1458.           
  1459.           The maximum  used sample  value.    For  example,  if  the  image
  1460.           consists of  6-bit data  low-order-justified  into  8-bit  bytes,
  1461.           MaxSampleValue will  be no  greater than 63. This is field is not
  1462.           to be  used to  affect the  visual appearance  of the  image when
  1463.           displayed.   Nor should  the values  of  this  field  affect  the
  1464.           interpretation of  any other  field.    Use  it  for  statistical
  1465.           purposes only.
  1466.           
  1467.           Default is 2**(BitsPerSample) - 1.
  1468.           
  1469.  
  1470.  
  1471.  
  1472.  
  1473.  
  1474.  
  1475.  
  1476.  
  1477.  
  1478.           TIFF 5.0                                          page 23
  1479.           TIFF 5.0                                          page 23
  1480.  
  1481.  
  1482.           
  1483.           MinSampleValue
  1484.           Tag  = 280  (118)
  1485.           Type = SHORT
  1486.           N    = SamplesPerPixel
  1487.           
  1488.           The minimum  used sample  value.  This field is not to be used to
  1489.           affect the  visual appearance  of the  image when displayed.  See
  1490.           the comments for MaxSampleValue.
  1491.           
  1492.           Default is 0.
  1493.           
  1494.           
  1495.           SubfileType
  1496.           Tag  = 255  (FF)
  1497.           Type = SHORT
  1498.           N    = 1
  1499.           
  1500.           A general  indication of  the kind  of data  that is contained in
  1501.           this subfile.  Currently defined values are:
  1502.           
  1503.           1 =  full  resolution  image  data_ImageWidth,  ImageLength,  and
  1504.           StripOffsets are required fields; and
  1505.           2 =  reduced resolution  image data_ImageWidth,  ImageLength, and
  1506.           StripOffsets are  required fields.   It is further assumed that a
  1507.           reduced resolution  image is  a reduced  version  of  the  entire
  1508.           extent of the corresponding full resolution data.
  1509.           3 =  single page  of a  multi-page image  (see the PageNumber tag
  1510.           description).
  1511.           
  1512.           Note that several image types can be found in a single TIFF file,
  1513.           with each subfile described by its own IFD.
  1514.           
  1515.           No default.
  1516.           
  1517.           Continued use  of this  field is not recommended.  Writers should
  1518.           instead use the new and more general NewSubfileType field.
  1519.           
  1520.           
  1521.           Orientation
  1522.           Tag  = 274 (112)
  1523.           Type = SHORT
  1524.           N    = 1
  1525.           
  1526.           1 =  The 0th  row represents the visual top of the image, and the
  1527.           0th column represents the visual left hand side.
  1528.           2 =  The 0th  row represents the visual top of the image, and the
  1529.           0th column represents the visual right hand side.
  1530.           3 =  The 0th  row represents  the visual bottom of the image, and
  1531.           the 0th column represents the visual right hand side.
  1532.           4 =  The 0th  row represents  the visual bottom of the image, and
  1533.           the 0th column represents the visual left hand side.
  1534.           5 =  The 0th  row represents  the visual  left hand  side of  the
  1535.           image, and the 0th column represents the visual top.
  1536.  
  1537.  
  1538.  
  1539.  
  1540.  
  1541.  
  1542.  
  1543.  
  1544.  
  1545.           TIFF 5.0                                          page 24
  1546.           TIFF 5.0                                          page 24
  1547.  
  1548.  
  1549.           6 =  The 0th  row represents  the visual  right hand  side of the
  1550.           image, and the 0th column represents the visual top.
  1551.           7 =  The 0th  row represents  the visual  right hand  side of the
  1552.           image, and the 0th column represents the visual bottom.
  1553.           8 =  The 0th  row represents  the visual  left hand  side of  the
  1554.           image, and the 0th column represents the visual bottom.
  1555.           
  1556.           Default is 1.
  1557.           
  1558.           This field is recommended for private (non-interchange) use only.
  1559.           It is extremely costly for most readers to perform image rotation
  1560.           _on the  fly,_ i.e.,  when importing  and printing;  and users of
  1561.           most  desktop  publishing  applications  do  not  expect  a  file
  1562.           imported by the application to be altered permanently in any way.
  1563.           
  1564.           
  1565.           Threshholding
  1566.           Tag  = 263  (107)
  1567.           Type = SHORT
  1568.           N    = 1
  1569.           
  1570.           1 = a bilevel _line art_  scan.  BitsPerSample must be 1.
  1571.           2 =  a _dithered_   scan, usually of continuous tone data such as
  1572.           photographs. BitsPerSample must be 1.
  1573.           3 = Error Diffused.
  1574.           
  1575.           Default is Threshholding = 1.  See also CellWidth, CellLength.
  1576.           4) Private Fields
  1577.           
  1578.           An organization  may wish to store information that is meaningful
  1579.           to only that organization in a TIFF file.  Tags numbered 32768 or
  1580.           higher  are  reserved  for  that  purpose.    Upon  request,  the
  1581.           administrator will  allocate and register a block of private tags
  1582.           for an  organization, to  avoid  possible  conflicts  with  other
  1583.           organizations.   Tags are  normally allocated  in blocks of five.
  1584.           If that is not enough, feel free to ask for more. You do not need
  1585.           to tell  the TIFF administrator or anyone else what you are going
  1586.           to use them for.
  1587.           
  1588.           Private enumerated  values  can  be  accommodated  in  a  similar
  1589.           fashion.   For example,  you may  wish to  experiment with  a new
  1590.           compression scheme  within TIFF.   Enumeration constants numbered
  1591.           32768 or  higher are  reserved for  private usage.  Upon request,
  1592.           the  administrator   will  allocate   and  register  a  block  of
  1593.           enumerated values  for a  particular field  (Compression, in  our
  1594.           example), to avoid possible conflicts.
  1595.           
  1596.           Tags and  values which  are allocated in the private number range
  1597.           are not  prohibited from  being included  in a future revision of
  1598.           this specification.   Several  such instances can be found in the
  1599.           TIFF specification.
  1600.           
  1601.           Do not  choose your  own tag  numbers.  If you do, it could cause
  1602.           serious problems some day.
  1603.  
  1604.  
  1605.  
  1606.  
  1607.  
  1608.  
  1609.  
  1610.  
  1611.  
  1612.           TIFF 5.0                                          page 25
  1613.           TIFF 5.0                                          page 25
  1614.  
  1615.  
  1616.           
  1617.           
  1618.           5) Image File Format Issues
  1619.           
  1620.           In the  quest to  give users no reason NOT to buy a product, some
  1621.           scanning and  image editing  applications overwhelm users with an
  1622.           incredible number  of _Save  As..._ options.  Let_s get rid of as
  1623.           many of  these as  we possibly  can.   For example, a single TIFF
  1624.           choice should  suffice once most major readers are supporting the
  1625.           three TIFF compression schemes; then writers can always compress.
  1626.           And given  TIFF_s flexibility,  including private  tag and  image
  1627.           editing  support   features,  there  does  not  seem  to  be  any
  1628.           legitimate reason  for continuing  to  write  image  files  using
  1629.           proprietary formats.
  1630.           
  1631.           Along the  same lines,  there is no excuse for making a user have
  1632.           to know  the file  format of  a file  that is  to be  read by  an
  1633.           application program.   TIFF  files, as  well as  most other  file
  1634.           formats, contain  sufficient information  to enable  software  to
  1635.           automatically and  reliably distinguish  one type  of  file  from
  1636.           another.
  1637.           
  1638.           
  1639.           6) For Further Information
  1640.           
  1641.           Contact the  Aldus Developers_ Desk for sample TIFF files, source
  1642.           code fragments,  and  a  list  of  features  that  are  currently
  1643.           supported in  Aldus products.   The Aldus Developers_ Desk is the
  1644.           current _TIFF administrator._
  1645.           
  1646.           Various TIFF  related  aids  are  found  in  Microsoft_s  Windows
  1647.           Developers Tookit for developers writing Windows applications.
  1648.           
  1649.           Finally, a  number of  scanner vendors are providing various TIFF
  1650.           services, such  as helping  to distribute  the TIFF specification
  1651.           and answering  TIFF questions.   Contact  the appropriate product
  1652.           manager or developer support service group.
  1653.           
  1654.  
  1655.  
  1656.  
  1657.  
  1658.  
  1659.  
  1660.  
  1661.  
  1662.  
  1663.  
  1664.  
  1665.  
  1666.  
  1667.  
  1668.  
  1669.  
  1670.  
  1671.  
  1672.  
  1673.  
  1674.  
  1675.  
  1676.  
  1677.  
  1678.  
  1679.           TIFF 5.0                                          page 26
  1680.           TIFF 5.0                                          page 26
  1681.  
  1682.  
  1683.           Appendix A:  Tag Structure Rationale
  1684.           
  1685.           
  1686.           A file  format is  defined by  both form (structure) and content.
  1687.           The content of TIFF consists of definitions of individual fields.
  1688.           It is therefore the content that we are ultimately interested in.
  1689.           The structure  merely tells  us how  to find the fields.  Yet the
  1690.           structure deserves  serious consideration for a number of reasons
  1691.           that are not at all obvious at first glance.  Since the structure
  1692.           described  herein   departs  significantly   from  several  other
  1693.           approaches, it may be useful to discuss the rationale behind it.
  1694.           
  1695.           The simplest,  most straightforward  structure for something like
  1696.           an image  file is  a positional  format.  In a positional scheme,
  1697.           the location  of the  data defines  what the  data  means.    For
  1698.           example, the  field for  _number of  rows_ might  begin  at  byte
  1699.           offset 30 in the image file.
  1700.           
  1701.           This approach  is simple and easy to implement and is perfect for
  1702.           static environments.   But  if a  significant amount  of  ongoing
  1703.           change must  be accommodated,  subtle problems  begin to  appear.
  1704.           For example,  suppose that  a field  must be superseded by a new,
  1705.           more general  field.  You could bump a version number to flag the
  1706.           change.   Then  new  software  has  no  problem  doing  something
  1707.           sensible with  old data, and all old software will reject the new
  1708.           data, even  software that  didn_t care about the old field.  This
  1709.           may seem like no more than a minor annoyance at first glance, but
  1710.           causing old  software to  break more  often than  it would really
  1711.           need to  can be very costly and, inevitably, causes much gnashing
  1712.           of teeth among customers.
  1713.           
  1714.           Furthermore, it  can be  avoided.   One approach  is to  store  a
  1715.           _valid_ flag  bit for each field.  Now you don_t have to bump the
  1716.           version number,  as long  as you  can put the new field somewhere
  1717.           that doesn_t  disturb any  of the  old fields.  Old software that
  1718.           didn_t care about that old field anyway can continue to function.
  1719.           (Old software  that did  care will of course have to give up, but
  1720.           this is an unavoidable price to be paid for the sake of progress,
  1721.           barring total omniscience.)
  1722.           
  1723.           Another problem  that crops  up frequently is that certain fields
  1724.           are likely  to make  sense only  if  other  fields  have  certain
  1725.           values.   This is not such a serious problem in practice; it just
  1726.           makes things  more confusing.   Nevertheless,  we note  that  the
  1727.           _valid_ flag bits described in the previous paragraph can help to
  1728.           clarify the situation.
  1729.           
  1730.           Field-dumping  programs   can  be  very  helpful  for  diagnostic
  1731.           purposes.   A desirable  characteristic of such a program is that
  1732.           it doesn_t  have to  know much  about what  it is  dumping.    In
  1733.           particular, it would be nice if the program could dump ASCII data
  1734.           in ASCII  format, integer  data in  integer format,  and  so  on,
  1735.           without having  to teach  the program  about new  fields all  the
  1736.           time.   So maybe  we should  add a  _data type_  component to our
  1737.  
  1738.  
  1739.  
  1740.  
  1741.  
  1742.  
  1743.  
  1744.  
  1745.  
  1746.           TIFF 5.0                                          page 27
  1747.           TIFF 5.0                                          page 27
  1748.  
  1749.  
  1750.           fields, plus  information on  how long  the field is, so that our
  1751.           dump program can walk through the fields without knowing what the
  1752.           fields _mean."
  1753.           
  1754.           But note  that if we add one more component to each field, namely
  1755.           a tag  that tells  what the field means, we can dispense with the
  1756.           _valid_ flag  bits, and  we can  also avoid  wasting space on the
  1757.           non-valid fields in the file.  Simple image creation applications
  1758.           can write out several fields and be done.
  1759.           
  1760.           We have  now derived  the essentials  of a  tag-based image  file
  1761.           format.
  1762.           
  1763.           Finally, a  caveat.  A tag based scheme cannot guarantee painless
  1764.           growth.   But is  does provide  a useful  tool to  assist in  the
  1765.           process.
  1766.           
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789.  
  1790.  
  1791.  
  1792.  
  1793.  
  1794.  
  1795.  
  1796.  
  1797.  
  1798.  
  1799.  
  1800.  
  1801.  
  1802.  
  1803.  
  1804.  
  1805.  
  1806.  
  1807.  
  1808.  
  1809.  
  1810.  
  1811.  
  1812.  
  1813.           TIFF 5.0                                          page 28
  1814.           TIFF 5.0                                          page 28
  1815.  
  1816.  
  1817.           Appendix B:  Data Compression_Scheme 2
  1818.           
  1819.           
  1820.           Abstract
  1821.           
  1822.           This document  describes a  method for  compressing bilevel  data
  1823.           that is  based on  the CCITT  Group 3  1D  facsimile  compression
  1824.           scheme.
  1825.           
  1826.           
  1827.           References
  1828.           
  1829.           1.   _Standardization of Group 3 facsimile apparatus for document
  1830.           transmission,_ Recommendation  T.4, Volume  VII, Fascicle  VII.3,
  1831.           Terminal Equipment  and Protocols  for  Telematic  Services,  The
  1832.           International  Telegraph  and  Telephone  Consultative  Committee
  1833.           (CCITT), Geneva, 1985, pages 16 through 31.
  1834.           2.   _Facsimile Coding  Schemes and  Coding Control Functions for
  1835.           Group 4  Facsimile Apparatus,_  Recommendation T.6,  Volume  VII,
  1836.           Fascicle VII.3,  Terminal Equipment  and Protocols  for Telematic
  1837.           Services, The  International Telegraph and Telephone Consultative
  1838.           Committee (CCITT), Geneva, 1985, pages 40 through 48.
  1839.           
  1840.           We do  not believe that these documents are necessary in order to
  1841.           implement Compression=2.   We  have included  (verbatim  in  most
  1842.           places) all the pertinent information in this Appendix.  However,
  1843.           if you  wish to  order the  documents, you  can  write  to  ANSI,
  1844.           Attention: Sales,  1430 Broadway, New York, N.Y., 10018.  Ask for
  1845.           the publication  listed above_it contains both Recommendation T.4
  1846.           and T.6.
  1847.           
  1848.           
  1849.           Relationship to the CCITT Specifications
  1850.           
  1851.           The  CCITT   Group  3   and  Group   4  specifications   describe
  1852.           communications protocols for a particular class of devices.  They
  1853.           are not  by themselves sufficient to describe a disk data format.
  1854.           Fortunately, however,  the CCITT  coding schemes  can be  readily
  1855.           adapted to this different environment.  The following is one such
  1856.           adaptation.   Most of  the language  is copied  directly from the
  1857.           CCITT specifications.
  1858.           
  1859.           
  1860.           Coding Scheme
  1861.           
  1862.           A line  (row) of  data is composed of a series of variable length
  1863.           code words.  Each code word represents a run length of either all
  1864.           white or  all black.   (Actually,  more than one code word may be
  1865.           required to  code a  given run,  in a  manner  described  below.)
  1866.           White runs and black runs alternate.
  1867.           
  1868.           In order  to ensure  that the  receiver (decompressor)  maintains
  1869.           color synchronization, all data lines will begin with a white run
  1870.           length code  word set.   If  the actual  scan line  begins with a
  1871.  
  1872.  
  1873.  
  1874.  
  1875.  
  1876.  
  1877.  
  1878.  
  1879.  
  1880.           TIFF 5.0                                          page 29
  1881.           TIFF 5.0                                          page 29
  1882.  
  1883.  
  1884.           black run,  a white  run length  of zero  will be sent (written).
  1885.           Black or  white run  lengths are  defined by  the code  words  in
  1886.           Tables 1  and 2.   The  code words are of two types:  Terminating
  1887.           code  words   and  Make-up  code  words.    Each  run  length  is
  1888.           represented by  zero or  more  Make-up  code  words  followed  by
  1889.           exactly one Terminating code word.
  1890.           
  1891.           Run lengths  in the  range of  0 to  63 pels (pixels) are encoded
  1892.           with their appropriate Terminating code word.  Note that there is
  1893.           a different list of code words for black and white run lengths.
  1894.           
  1895.           Run lengths in the range of 64 to 2623 (2560+63) pels are encoded
  1896.           first by  the Make-up  code word representing the run length that
  1897.           is nearest  to, not  longer than,  that required.   This  is then
  1898.           followed by the Terminating code word representing the difference
  1899.           between the required run length and the run length represented by
  1900.           the Make-up code.
  1901.           
  1902.           Run lengths  in the range of lengths longer than or equal to 2624
  1903.           pels are  coded first  by the  Make-up code  of  2560.    If  the
  1904.           remaining part  of the run (after the first Make-up code of 2560)
  1905.           is 2560  pels or  greater, additional Make-up code(s) of 2560 are
  1906.           issued until the remaining part of the run becomes less than 2560
  1907.           pels.   Then  the  remaining  part  of  the  run  is  encoded  by
  1908.           Terminating code  or  by  Make-up  code  plus  Terminating  code,
  1909.           according to the range mentioned above.
  1910.           
  1911.           It is  considered an  unrecoverable error  if the  sum of the run
  1912.           lengths for  a line  does not  equal the  value of the ImageWidth
  1913.           field.
  1914.           
  1915.           New rows always begin on the next available byte boundary.
  1916.           
  1917.           No EOL  code words  are used.   No fill bits are used, except for
  1918.           the ignored  bits at  the end  of the last byte of a row.  RTC is
  1919.           not used.
  1920.           
  1921.           
  1922.           Table 1/T.4  Terminating codes
  1923.           
  1924.           
  1925.           White          Black
  1926.            run Code  run Code
  1927.           length    word length    word
  1928.            ----     ---- ------    ----
  1929.           
  1930.            0   00110101   0   0000110111
  1931.            1   000111     1   010
  1932.            2   0111  2   11
  1933.            3   1000  3   10
  1934.            4   1011  4   011
  1935.            5   1100  5   0011
  1936.            6   1110  6   0010
  1937.            7   1111  7   00011
  1938.  
  1939.  
  1940.  
  1941.  
  1942.  
  1943.  
  1944.  
  1945.  
  1946.  
  1947.           TIFF 5.0                                          page 30
  1948.           TIFF 5.0                                          page 30
  1949.  
  1950.  
  1951.            8   10011      8   000101
  1952.            9   10100      9   000100
  1953.           10   00111     10   0000100
  1954.           11   01000     11   0000101
  1955.           12   001000    12   0000111
  1956.           13   000011    13   00000100
  1957.           14   110100    14   00000111
  1958.           15   110101    15   000011000
  1959.           16   101010    16   0000010111
  1960.           17   101011    17   0000011000
  1961.           18   0100111   18   0000001000
  1962.           19   0001100   19   00001100111
  1963.           20   0001000   20   00001101000
  1964.           21   0010111   21   00001101100
  1965.           22   0000011   22   00000110111
  1966.           23   0000100   23   00000101000
  1967.           24   0101000   24   00000010111
  1968.           25   0101011   25   00000011000
  1969.           26   0010011   26   000011001010
  1970.           27   0100100   27   000011001011
  1971.           28   0011000   28   000011001100
  1972.           29   00000010  29   000011001101
  1973.           30   00000011  30   000001101000
  1974.           31   00011010  31   000001101001
  1975.           32   00011011  32   000001101010
  1976.           33   00010010  33   000001101011
  1977.           34   00010011  34   000011010010
  1978.           35   00010100  35   000011010011
  1979.           36   00010101  36   000011010100
  1980.           37   00010110  37   000011010101
  1981.           38   00010111  38   000011010110
  1982.           39   00101000  39   000011010111
  1983.           40   00101001  40   000001101100
  1984.           41   00101010  41   000001101101
  1985.           42   00101011  42   000011011010
  1986.           43   00101100  43   000011011011
  1987.           44   00101101  44   000001010100
  1988.           45   00000100  45   000001010101
  1989.           46   00000101  46   000001010110
  1990.           47   00001010  47   000001010111
  1991.           48   00001011  48   000001100100
  1992.           49   01010010  49   000001100101
  1993.           50   01010011  50   000001010010
  1994.           51   01010100  51   000001010011
  1995.           52   01010101  52   000000100100
  1996.           53   00100100  53   000000110111
  1997.           54   00100101  54   000000111000
  1998.           55   01011000  55   000000100111
  1999.           56   01011001  56   000000101000
  2000.           57   01011010  57   000001011000
  2001.           58   01011011  58   000001011001
  2002.           59   01001010  59   000000101011
  2003.           60   01001011  60   000000101100
  2004.           61   00110010  61   000001011010
  2005.  
  2006.  
  2007.  
  2008.  
  2009.  
  2010.  
  2011.  
  2012.  
  2013.  
  2014.           TIFF 5.0                                          page 31
  2015.           TIFF 5.0                                          page 31
  2016.  
  2017.  
  2018.           62   00110011  62   000001100110
  2019.           63   00110100  63   000001100111   
  2020.           
  2021.           
  2022.           
  2023.           
  2024.           Table 2/T.4  Make-up codes
  2025.           
  2026.           White          Black
  2027.            run Code  run Code
  2028.           length    word      length    word
  2029.           ------    ---- ------    ----
  2030.           
  2031.             64 11011       64 0000001111
  2032.            128 10010      128 000011001000
  2033.            192 010111     192 000011001001
  2034.            256 0110111    256 000001011011
  2035.            320 00110110   320 000000110011
  2036.            384 00110111   384 000000110100
  2037.            448 01100100   448 000000110101
  2038.            512 01100101   512 0000001101100
  2039.            576 01101000   576 0000001101101
  2040.            640 01100111   640 0000001001010
  2041.            704 011001100  704 0000001001011
  2042.            768 011001101  768 0000001001100
  2043.            832 011010010  832 0000001001101
  2044.            896 011010011  896 0000001110010
  2045.            960 011010100  960 0000001110011
  2046.           1024 011010101 1024 0000001110100
  2047.           1088 011010110 1088 0000001110101
  2048.           1152 011010111 1152 0000001110110
  2049.           1216 011011000 1216 0000001110111
  2050.           1280 011011001 1280 0000001010010
  2051.           1344 011011010 1344 0000001010011
  2052.           1408 011011011 1408 0000001010100
  2053.           1472 010011000 1472 0000001010101
  2054.           1536 010011001 1536 0000001011010
  2055.           1600 010011010 1600 0000001011011
  2056.           1664 011000    1664 0000001100100
  2057.           1728 010011011 1728 0000001100101
  2058.            EOL 000000000001    EOL 000000000001
  2059.           
  2060.           
  2061.           
  2062.           
  2063.           Additional make-up codes
  2064.           
  2065.           White
  2066.           and
  2067.           Black     Make-up
  2068.           run  code
  2069.           length    word
  2070.           ------    ----
  2071.           
  2072.  
  2073.  
  2074.  
  2075.  
  2076.  
  2077.  
  2078.  
  2079.  
  2080.  
  2081.           TIFF 5.0                                          page 32
  2082.           TIFF 5.0                                          page 32
  2083.  
  2084.  
  2085.           1792 00000001000
  2086.           1856 00000001100
  2087.           1920 00000001101
  2088.           1984 000000010010
  2089.           2048 000000010011
  2090.           2112 000000010100
  2091.           2176 000000010101
  2092.           2240 000000010110
  2093.           2304 000000010111
  2094.           2368 000000011100
  2095.           2432 000000011101
  2096.           2496 000000011110
  2097.           2560 000000011111
  2098.           
  2099.           
  2100.           
  2101.           
  2102.  
  2103.  
  2104.  
  2105.  
  2106.  
  2107.  
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117.  
  2118.  
  2119.  
  2120.  
  2121.  
  2122.  
  2123.  
  2124.  
  2125.  
  2126.  
  2127.  
  2128.  
  2129.  
  2130.  
  2131.  
  2132.  
  2133.  
  2134.  
  2135.  
  2136.  
  2137.  
  2138.  
  2139.  
  2140.  
  2141.  
  2142.  
  2143.  
  2144.  
  2145.  
  2146.  
  2147.  
  2148.           TIFF 5.0                                          page 33
  2149.           TIFF 5.0                                          page 33
  2150.  
  2151.  
  2152.           Appendix C: Data Compression_Scheme 32773_
  2153.           _PackBits_
  2154.           
  2155.           
  2156.           Abstract
  2157.           
  2158.           This document  describes a  simple compression scheme for bilevel
  2159.           scanned and paint type files.
  2160.           
  2161.           
  2162.           Motivation
  2163.           
  2164.           The TIFF  specification defines  a number of compression schemes.
  2165.           Compression type  1 is  really no  compression, other  than basic
  2166.           pixel  packing.     Compression   type  2,   based  on  CCITT  1D
  2167.           compression,  is   powerful,  but   not  trivial   to  implement.
  2168.           Compression type  5 is  typically very effective for most bilevel
  2169.           images, as  well as  many deeper images such as palette color and
  2170.           grayscale images, but is also not trivial to implement.  PackBits
  2171.           is a simple but often effective alternative.
  2172.           
  2173.           
  2174.           Description
  2175.           
  2176.           Several good schemes were already in use in various settings.  We
  2177.           somewhat arbitrarily picked the Macintosh PackBits scheme.  It is
  2178.           byte oriented,  so there  is no problem with word alignment.  And
  2179.           it has a good worst case behavior (at most 1 extra byte for every
  2180.           128 input  bytes).    For  Macintosh  users,  there  are  toolbox
  2181.           utilities PackBits  and UnPackBits that will do the work for you,
  2182.           but it is easy to implement your own routines.
  2183.           
  2184.           A pseudo code fragment to unpack might look like this:
  2185.           
  2186.           Loop  until  you  get  the  number  of  unpacked  bytes  you  are
  2187.           expecting:
  2188.                Read the next source byte into n.
  2189.                If n is between 0 and 127 inclusive, copy the next n+1 bytes
  2190.           literally.
  2191.                Else if  n is  between -127  and -1 inclusive, copy the next
  2192.           byte -n+1 times.
  2193.                Else if n is 128, noop.
  2194.           Endloop
  2195.           
  2196.           In the  inverse routine,  it_s best to encode a 2-byte repeat run
  2197.           as a replicate run except when preceded and followed by a literal
  2198.           run, in  which case it_s best to merge the three into one literal
  2199.           run.  Always encode 3-byte repeats as replicate runs.
  2200.           
  2201.           So that_s the algorithm.  Here are some other rules:
  2202.           
  2203.           ╤    Each row  must be packed separately.  Do not compress across
  2204.           row boundaries.
  2205.  
  2206.  
  2207.  
  2208.  
  2209.  
  2210.  
  2211.  
  2212.  
  2213.  
  2214.  
  2215.           TIFF 5.0                                          page 34
  2216.           TIFF 5.0                                          page 34
  2217.  
  2218.  
  2219.           ╤    The number  of uncompressed  bytes per  row is defined to be
  2220.           (ImageWidth +  7) / 8.  If the uncompressed bitmap is required to
  2221.           have an  even number  of bytes  per row,  decompress  into  word-
  2222.           aligned buffers.
  2223.           ╤    If a  run is  larger  than  128  bytes,  simply  encode  the
  2224.           remainder of the run as one or more additional replicate runs.
  2225.           
  2226.           When  PackBits   data  is  uncompressed,  the  result  should  be
  2227.           interpreted as per compression type 1 (no compression).
  2228.           
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.  
  2249.  
  2250.  
  2251.  
  2252.  
  2253.  
  2254.  
  2255.  
  2256.  
  2257.  
  2258.  
  2259.  
  2260.  
  2261.  
  2262.  
  2263.  
  2264.  
  2265.  
  2266.  
  2267.  
  2268.  
  2269.  
  2270.  
  2271.  
  2272.  
  2273.  
  2274.  
  2275.  
  2276.  
  2277.  
  2278.  
  2279.  
  2280.  
  2281.  
  2282.           TIFF 5.0                                          page 35
  2283.           TIFF 5.0                                          page 35
  2284.  
  2285.  
  2286.           Appendix D
  2287.           
  2288.           
  2289.           Appendix D  has been  deleted.   It formerly contained guidelines
  2290.           for passing  TIFF files on the Microsoft Windows Clipboard.  This
  2291.           was judged to not be a good idea, in light of the ever-increasing
  2292.           size of  scanned images.   Applications are instead encouraged to
  2293.           employ file-based  mechanisms to  exchange  TIFF  data.    Aldus_
  2294.           PageMaker, for  example, implements  a _File  Place_  command  to
  2295.           allow TIFF files to be imported.
  2296.           
  2297.  
  2298.  
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.  
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.  
  2315.  
  2316.  
  2317.  
  2318.  
  2319.  
  2320.  
  2321.  
  2322.  
  2323.  
  2324.  
  2325.  
  2326.  
  2327.  
  2328.  
  2329.  
  2330.  
  2331.  
  2332.  
  2333.  
  2334.  
  2335.  
  2336.  
  2337.  
  2338.  
  2339.  
  2340.  
  2341.  
  2342.  
  2343.  
  2344.  
  2345.  
  2346.  
  2347.  
  2348.  
  2349.           TIFF 5.0                                          page 36
  2350.           TIFF 5.0                                          page 36
  2351.  
  2352.  
  2353.           Appendix E:  Numerical List of TIFF Tags
  2354.           
  2355.           
  2356.           NewSubfileType
  2357.           Tag  =  254  (FE)
  2358.           Type = LONG
  2359.           N    = 1
  2360.           
  2361.           SubfileType
  2362.           Tag  = 255  (FF)
  2363.           Type = SHORT
  2364.           N    = 1
  2365.           
  2366.           ImageWidth
  2367.           Tag  = 256  (100)
  2368.           Type = SHORT or LONG
  2369.           N    = 1
  2370.           
  2371.           ImageLength
  2372.           Tag  = 257  (101)
  2373.           Type = SHORT or LONG
  2374.           N    = 1
  2375.           
  2376.           BitsPerSample
  2377.           Tag  = 258  (102)
  2378.           Type = SHORT
  2379.           N    = SamplesPerPixel
  2380.           
  2381.           Compression
  2382.           Tag  = 259  (103)
  2383.           Type = SHORT
  2384.           N    = 1
  2385.           
  2386.           PhotometricInterpretation
  2387.           Tag  = 262  (106)
  2388.           Type = SHORT
  2389.           N    = 1
  2390.           
  2391.           
  2392.           Threshholding
  2393.           Tag  = 263  (107)
  2394.           Type = SHORT
  2395.           N    = 1
  2396.           
  2397.           CellWidth
  2398.           Tag  = 264  (108)
  2399.           Type = SHORT
  2400.           N    = 1
  2401.           
  2402.           CellLength
  2403.           Tag  = 265  (109)
  2404.           Type = SHORT
  2405.           N    = 1
  2406.           
  2407.  
  2408.  
  2409.  
  2410.  
  2411.  
  2412.  
  2413.  
  2414.  
  2415.  
  2416.           TIFF 5.0                                          page 37
  2417.           TIFF 5.0                                          page 37
  2418.  
  2419.  
  2420.           FillOrder
  2421.           Tag  = 266  (10A)
  2422.           Type = SHORT
  2423.           N    = 1
  2424.           
  2425.           DocumentName
  2426.           Tag  = 269  (10D)
  2427.           Type = ASCII
  2428.           
  2429.           ImageDescription
  2430.           Tag  = 270 (10E)
  2431.           Type = ASCII
  2432.           
  2433.           Make
  2434.           Tag  = 271  (10F)
  2435.           Type = ASCII
  2436.           
  2437.           Model
  2438.           Tag  = 272  (110)
  2439.           Type = ASCII
  2440.           
  2441.           StripOffsets
  2442.           Tag  = 273  (111)
  2443.           Type = SHORT or LONG
  2444.           N    = StripsPerImage for PlanarConfiguration equal to 1.
  2445.                = SamplesPerPixel  * StripsPerImage  for PlanarConfiguration
  2446.           equal to 2
  2447.           
  2448.           Orientation
  2449.           Tag  = 274 (112)
  2450.           Type = SHORT
  2451.           N    = 1
  2452.           
  2453.           SamplesPerPixel
  2454.           Tag  = 277  (115)
  2455.           Type = SHORT
  2456.           N    = 1
  2457.           
  2458.           RowsPerStrip
  2459.           Tag  = 278  (116)
  2460.           Type = SHORT or LONG
  2461.           N    = 1
  2462.           
  2463.           StripByteCounts
  2464.           Tag  = 279  (117)
  2465.           Type = LONG or SHORT
  2466.           N    = StripsPerImage for PlanarConfiguration equal to 1.
  2467.                = SamplesPerPixel  * StripsPerImage  for PlanarConfiguration
  2468.           equal to 2.
  2469.           
  2470.           MinSampleValue
  2471.           Tag  = 280  (118)
  2472.           Type = SHORT
  2473.           N    = SamplesPerPixel
  2474.  
  2475.  
  2476.  
  2477.  
  2478.  
  2479.  
  2480.  
  2481.  
  2482.  
  2483.           TIFF 5.0                                          page 38
  2484.           TIFF 5.0                                          page 38
  2485.  
  2486.  
  2487.           
  2488.           MaxSampleValue
  2489.           Tag  = 281  (119)
  2490.           Type = SHORT
  2491.           N    = SamplesPerPixel
  2492.           
  2493.           XResolution
  2494.           Tag  = 282  (11A)
  2495.           Type = RATIONAL
  2496.           N    = 1
  2497.           
  2498.           YResolution
  2499.           Tag  = 283  (11B)
  2500.           Type = RATIONAL
  2501.           N    = 1
  2502.           
  2503.           PlanarConfiguration
  2504.           Tag  = 284  (11C)
  2505.           Type = SHORT
  2506.           N    = 1
  2507.           
  2508.           PageName
  2509.           Tag  = 285  (11D)
  2510.           Type = ASCII
  2511.           
  2512.           
  2513.           XPosition
  2514.           Tag  = 286  (11E)
  2515.           Type = RATIONAL
  2516.           
  2517.           YPosition
  2518.           Tag  = 287  (11F)
  2519.           Type = RATIONAL
  2520.           
  2521.           FreeOffsets
  2522.           Tag  = 288  (120)
  2523.           Type = LONG
  2524.           
  2525.           FreeByteCounts
  2526.           Tag  = 289  (121)
  2527.           Type = LONG
  2528.           
  2529.           GrayResponseUnit
  2530.           Tag  = 290 (122)
  2531.           Type = SHORT
  2532.           N    = 1
  2533.           
  2534.           GrayResponseCurve
  2535.           Tag  = 291 (123)
  2536.           Type = SHORT
  2537.           N    = 2**BitsPerSample
  2538.           
  2539.           Group3Options
  2540.           Tag  = 292  (124)
  2541.  
  2542.  
  2543.  
  2544.  
  2545.  
  2546.  
  2547.  
  2548.  
  2549.  
  2550.           TIFF 5.0                                          page 39
  2551.           TIFF 5.0                                          page 39
  2552.  
  2553.  
  2554.           Type = LONG
  2555.           N    = 1
  2556.           
  2557.           Group4Options
  2558.           Tag  =  293  (125)
  2559.           Type = LONG
  2560.           N    = 1
  2561.           
  2562.           ResolutionUnit
  2563.           Tag  = 296 (128)
  2564.           Type = SHORT
  2565.           N    = 1
  2566.           
  2567.           PageNumber
  2568.           Tag  = 297  (129)
  2569.           Type = SHORT
  2570.           N    = 2
  2571.           
  2572.           ColorResponseCurves
  2573.           Tag  = 301 (12D)
  2574.           Type = SHORT
  2575.           N    = 3 * (2**BitsPerSample)
  2576.           
  2577.           Software
  2578.           Tag  = 305  (131)
  2579.           Type = ASCII
  2580.           
  2581.           DateTime
  2582.           Tag  = 306  (132)
  2583.           Type = ASCII
  2584.           N    = 20
  2585.           
  2586.           Artist
  2587.           Tag  = 315  (13B)
  2588.           Type = ASCII
  2589.           
  2590.           HostComputer
  2591.           Tag  = 316  (13C)
  2592.           Type = ASCII
  2593.           
  2594.           Predictor
  2595.           Tag  = 317 (13D)
  2596.           Type = SHORT
  2597.           N    = 1
  2598.           
  2599.           WhitePoint
  2600.           Tag  = 318 (13E)
  2601.           Type = RATIONAL
  2602.           N    = 2
  2603.           
  2604.           PrimaryChromaticities
  2605.           Tag  = 319 (13F)
  2606.           Type = RATIONAL
  2607.           N    = 6
  2608.  
  2609.  
  2610.  
  2611.  
  2612.  
  2613.  
  2614.  
  2615.  
  2616.  
  2617.           TIFF 5.0                                          page 40
  2618.           TIFF 5.0                                          page 40
  2619.  
  2620.  
  2621.           
  2622.           ColorMap
  2623.           Tag  = 320 (140)
  2624.           Type = SHORT
  2625.           N    = 3 * (2**BitsPerSample)
  2626.           
  2627.  
  2628.  
  2629.  
  2630.  
  2631.  
  2632.  
  2633.  
  2634.  
  2635.  
  2636.  
  2637.  
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.  
  2645.  
  2646.  
  2647.  
  2648.  
  2649.  
  2650.  
  2651.  
  2652.  
  2653.  
  2654.  
  2655.  
  2656.  
  2657.  
  2658.  
  2659.  
  2660.  
  2661.  
  2662.  
  2663.  
  2664.  
  2665.  
  2666.  
  2667.  
  2668.  
  2669.  
  2670.  
  2671.  
  2672.  
  2673.  
  2674.  
  2675.  
  2676.  
  2677.  
  2678.  
  2679.  
  2680.  
  2681.  
  2682.  
  2683.  
  2684.           TIFF 5.0                                          page 41
  2685.           TIFF 5.0                                          page 41
  2686.  
  2687.  
  2688.           Appendix F:  Data Compression_Scheme 5_LZW
  2689.           Compression
  2690.           
  2691.           
  2692.           Abstract
  2693.           
  2694.           This document describes an adaptive compression scheme for raster
  2695.           images.
  2696.           
  2697.           
  2698.           Reference
  2699.           
  2700.           Terry  A.   Welch,  _A   Technique  for   High  Performance  Data
  2701.           Compression_,  IEEE   Computer,  vol.   17  no.  6  (June  1984).
  2702.           Describes the  basic Lempel-Ziv  & Welch  (LZW) algorithm.    The
  2703.           author_s goal  in the  article is  to describe  a  hardware-based
  2704.           compressor that could be built into a disk controller or database
  2705.           engine, and  used on  all types  of data.   There  is no specific
  2706.           discussion of  raster images.    We  intend  to  give  sufficient
  2707.           information in  this Appendix so that the article is not required
  2708.           reading.
  2709.           
  2710.           
  2711.           Requirements
  2712.           
  2713.           A compression  scheme with  the following  characteristics should
  2714.           work well in a desktop publishing environment:
  2715.           
  2716.           ╤    Must work well for images of any bit depth, including images
  2717.           deeper than 8 bits per sample.
  2718.           ╤    Must be effective:  an average compression ratio of at least
  2719.           2:1 or  better.    And  it  must  have  a  reasonable  worst-case
  2720.           behavior, in case something really strange is thrown at it.
  2721.           ╤    Should  not  depend  on  small  variations  between  pixels.
  2722.           Palette color  images tend  to contain  abrupt changes  in  index
  2723.           values, due to common patterning and dithering techniques.  These
  2724.           abrupt changes  do tend to be repetitive, however, and the scheme
  2725.           should make use of this fact.
  2726.           ╤    For images  generated by  paint programs,  the scheme should
  2727.           not depend on a particular pattern width.  8x8 pixel patterns are
  2728.           common now, but we should not assume that this situation will not
  2729.           change.
  2730.           ╤    Must be  fast.   It should  not take  more than 5 seconds to
  2731.           decompress a  100K byte  grayscale image on a 68020- or 386-based
  2732.           computer.   Compression can  be slower,  but probably not by more
  2733.           than a factor of 2 or 3.
  2734.           ╤    The level  of implementation  complexity must be reasonable.
  2735.           We would like something that can be implemented in no more than a
  2736.           couple of  weeks  by  a_competent  software  engineer  with  some
  2737.           experience  in   image  processing.     The   compiled  code  for
  2738.           compression and  decompression combined  should be  no more  than
  2739.           about 10K.
  2740.           ╤    Does not require floating point software or hardware.
  2741.           
  2742.  
  2743.  
  2744.  
  2745.  
  2746.  
  2747.  
  2748.  
  2749.  
  2750.  
  2751.           TIFF 5.0                                          page 42
  2752.           TIFF 5.0                                          page 42
  2753.  
  2754.  
  2755.           
  2756.           The following  sections describe  an algorithm based on the _LZW_
  2757.           (Lempel-Ziv & Welch) technique that meets the above requirements.
  2758.           In addition  meeting our  requirements,  LZW  has  the  following
  2759.           characteristics:
  2760.           
  2761.           ╤    LZW is fully reversible.  All information is preserved.  But
  2762.           if noise  or information  is removed  from an  image, perhaps  by
  2763.           smoothing or  zeroing some  low-order bitplanes,  LZW  compresses
  2764.           images to  a smaller  size.   Thus,   5-bit, 6-bit, or 7-bit data
  2765.           masquerading as  8-bit data  compresses better  than  true  8-bit
  2766.           data. Smooth  images also  compress better than noisy images, and
  2767.           simple images compress better than complex images.
  2768.           φ    On a  68082- or  386-based computer,  LZW  software  can  be
  2769.           written to  compress at  between 30K  and 80K  bytes per  second,
  2770.           depending on image characteristics.  LZW decompression speeds are
  2771.           typically about 50K bytes per second.
  2772.           φ    LZW works  well on  bilevel images,  too.   It always  beats
  2773.           PackBits,  and   generally  ties   CCITT  1D  (Modified  Huffman)
  2774.           compression, on our test images.  Tying CCITT 1D is impressive in
  2775.           that LZW  seems to be considerably faster than CCITT 1D, at least
  2776.           in our implementation.
  2777.           φ    Our implementation is written in C, and compiles to about 2K
  2778.           bytes of object code each for the compressor and decompressor.
  2779.           φ    One of  the nice  things about  LZW is that it is used quite
  2780.           widely in  other applications  such as  archival programs, and is
  2781.           therefore more of a known quantity.
  2782.           
  2783.           
  2784.           The Algorithm
  2785.           
  2786.           Each strip  is compressed  independently.   We strongly recommend
  2787.           that RowsPerStrip  be chosen  such that each strip contains about
  2788.           8K bytes  before compression.   We  want to keep the strips small
  2789.           enough so  that the  compressed and  uncompressed versions of the
  2790.           strip can  be kept entirely in memory even on small machines, but
  2791.           large enough to maintain nearly optimal compression ratios.
  2792.           
  2793.           The LZW  algorithm is  based on  a translation  table, or  string
  2794.           table, that  maps strings  of input  characters into  codes.  The
  2795.           TIFF implementation  uses variable-length  codes, with  a maximum
  2796.           code length of 12 bits.  This string table is different for every
  2797.           strip, and,  remarkably, does  not need to be kept around for the
  2798.           decompressor.     The  trick   is  to   make   the   decompressor
  2799.           automatically build  the same  table as is built when compressing
  2800.           the data.   We  use a  C-like pseudocode  to describe  the coding
  2801.           scheme:
  2802.           
  2803.                InitializeStringTable();
  2804.                WriteCode(ClearCode);
  2805.                _ = the empty string;
  2806.                for each character in the strip {
  2807.                     K = GetNextCharacter();
  2808.                     if _+K is in the string table {
  2809.  
  2810.  
  2811.  
  2812.  
  2813.  
  2814.  
  2815.  
  2816.  
  2817.  
  2818.           TIFF 5.0                                          page 43
  2819.           TIFF 5.0                                          page 43
  2820.  
  2821.  
  2822.                          _ = _+K;  /* string concatenation */
  2823.                     } else {
  2824.                          WriteCode (CodeFromString(_));
  2825.                          AddTableEntry(_+K);
  2826.                          _ = K;
  2827.                     }
  2828.                } /* end of for loop */
  2829.                WriteCode (CodeFromString(_));
  2830.                WriteCode (EndOfInformation);
  2831.                     
  2832.           That_s  it.    The  scheme  is  simple,  although  it  is  fairly
  2833.           challenging  to  implement  efficiently.    But  we  need  a  few
  2834.           explanations before we go on to decompression.
  2835.           
  2836.           The  _characters_   that  make  up  the  LZW  strings  are  bytes
  2837.           containing TIFF  uncompressed (Compression=1)  image data, in our
  2838.           implementation.   For example,  if BitsPerSample is 4, each 8-bit
  2839.           LZW character will contain two 4-bit pixels.  If BitsPerSample is
  2840.           16, each 16-bit pixel will span two 8-bit LZW characters.
  2841.           
  2842.           (It is  also possible to implement a version of LZW where the LZW
  2843.           character depth equals BitsPerSample, as was described by Draft 2
  2844.           of Revision  5.0.   But  there  is  a  major  problem  with  this
  2845.           approach.   If BitsPerSample  is greater  than 11, we can not use
  2846.           12-bit-maximum  codes,   so  that  the  resulting  LZW  table  is
  2847.           unacceptably large.   Fortunately,  due to the adaptive nature of
  2848.           LZW, we  do not  pay a  significant compression ratio penalty for
  2849.           combining several  pixels into  one byte before compressing.  For
  2850.           example, our  4-bit sample  images  compressed  about  3  percent
  2851.           worse, and  our 1-bit  images compressed  about 5 percent better.
  2852.           And it  is easier to write an LZW compressor that always uses the
  2853.           same character  depth than  it is  to write  one which can handle
  2854.           varying depths.)
  2855.           
  2856.           We can  now describe  some of the routine and variable references
  2857.           in our pseudocode:
  2858.           
  2859.           InitializeStringTable() initializes  the string  table to contain
  2860.           all possible  single-character strings.   There  are 256 of them,
  2861.           numbered 0 through 255, since our characters are bytes.
  2862.           
  2863.           WriteCode() writes  a code  to the output stream.  The first code
  2864.           written is a Clear code, which is defined to be code #256.
  2865.           
  2866.           _ is our _prefix string._
  2867.           
  2868.           GetNextCharacter() retrieves  the next  character value  from the
  2869.           input stream.   This  will be number between 0 and 255, since our
  2870.           characters are bytes.
  2871.           
  2872.           The _+_ signs indicate string concatenation.
  2873.           
  2874.           AddTableEntry() adds a table entry.  (InitializeStringTable() has
  2875.           already put  256 entries  in our table.  Each entry consists of a
  2876.  
  2877.  
  2878.  
  2879.  
  2880.  
  2881.  
  2882.  
  2883.  
  2884.  
  2885.           TIFF 5.0                                          page 44
  2886.           TIFF 5.0                                          page 44
  2887.  
  2888.  
  2889.           single-character string, and its associated code value, which is,
  2890.           in our  application, identical to the character itself.  That is,
  2891.           the 0th  entry in  our table  consists of  the string  <0>,  with
  2892.           corresponding code  value of  <0>, the  1st entry  in  the  table
  2893.           consists of the string <1>, with corresponding code value of <1>,
  2894.           ..., and  the 255th  entry in  our table  consists of  the string
  2895.           <255>, with  corresponding code  value of  <255>.)   So the first
  2896.           entry that  we add  to our  string table will be at position 256,
  2897.           right?   Well, not  quite, since  we will reserve code #256 for a
  2898.           special   _Clear_   code,   and   code   #257   for   a   special
  2899.           _EndOfInformation_ code  that we will write out at the end of the
  2900.           strip.  So the first multiple-character entry added to the string
  2901.           table will be at position 258.
  2902.           
  2903.           Let_s try  an example.   Suppose  we have  input data  that looks
  2904.           like:
  2905.           
  2906.           Pixel 0:  <7>
  2907.           Pixel 1:  <7>
  2908.           Pixel 2:  <7>
  2909.           Pixel 3:  <8>
  2910.           Pixel 4:  <8>
  2911.           Pixel 5:  <7>
  2912.           Pixel 6:  <7>
  2913.           Pixel 7:  <6>
  2914.           Pixel 8:  <6>
  2915.           
  2916.           First, we read Pixel 0 into K.  _K is then simply <7>, since _ is
  2917.           the empty string at this point.  Is the string <7> already in the
  2918.           string table?  Of course, since all single character strings were
  2919.           put in  the table  by InitializeStringTable().  So set _ equal to
  2920.           <7>, and go to the top of the loop.
  2921.           
  2922.           Read Pixel 1 into K.  Does _K (<7><7>) exist in the string table?
  2923.           No, so we get to do some real work.  We write the code associated
  2924.           with _  to output  (write <7>  to output), and add _K (<7><7>) to
  2925.           the table  as entry  258.   Store K  (<7>) into  _.    Note  that
  2926.           although we have added the string consisting of Pixel 0 and Pixel
  2927.           1 to  the table, we _re-use_ Pixel 1 as the beginning of the next
  2928.           string.
  2929.           
  2930.           Back at  the top  of the  loop.  We read Pixel 2 into K.  Does _K
  2931.           (<7><7>) exist  in the  string table?   Yes,  the entry  we  just
  2932.           added, entry 258, contains exactly <7><7>.  So we just add K onto
  2933.           the end of _, so that _ is now <7><7>.
  2934.           
  2935.           Back at  the top  of the  loop.  We read Pixel 3 into K.  Does _K
  2936.           (<7><7><8>) exist  in the  string table?   No,  so write the code
  2937.           associated with  _ (<258>)  to output, and add _K to the table as
  2938.           entry 259.  Store K (<8>) into _.
  2939.           
  2940.           Back at  the top  of the  loop.  We read Pixel 4 into K.  Does _K
  2941.           (<8><8>) exist  in the  string table?   No,  so  write  the  code
  2942.  
  2943.  
  2944.  
  2945.  
  2946.  
  2947.  
  2948.  
  2949.  
  2950.  
  2951.  
  2952.           TIFF 5.0                                          page 45
  2953.           TIFF 5.0                                          page 45
  2954.  
  2955.  
  2956.           associated with  _ (<8>)  to output,  and add  _K to the table as
  2957.           entry 260.  Store K (<8>) into _.
  2958.           
  2959.           Continuing, we get the following results:
  2960.           
  2961.                After reading: We write to output: And add table entry:
  2962.                Pixel 0
  2963.                Pixel 1   <7>  258: <7><7>
  2964.                Pixel 2
  2965.                Pixel 3   <258>     259: <7><7><8>
  2966.                Pixel 4   <8>  260: <8><8>
  2967.                Pixel 5   <8>  261: <8><7>
  2968.                Pixel 6
  2969.                Pixel 7   <258>     262: <7><7><6>
  2970.                Pixel 8   <6>  263: <6><6>
  2971.           
  2972.           WriteCode() also  requires some  explanation.   The  output  code
  2973.           stream,  <7><258><8><8><258><6>...  in  our  example,  should  be
  2974.           written using as few bits as possible.  When we are just starting
  2975.           out, we  can use  9-bit codes, since our new string table entries
  2976.           are greater  than 255  but less  than 512.  But when we add table
  2977.           entry 512,  we must  switch to 10-bit codes.  Likewise, we switch
  2978.           to 11-bit  codes at  1024, and  12-bit codes  at 2048.   We  will
  2979.           somewhat arbitrarily limit ourselves to 12-bit codes, so that our
  2980.           table can  have at most 4096 entries.  If we push it any farther,
  2981.           tables tend to get too large.
  2982.           
  2983.           What happens  if we run out of room in our string table?  This is
  2984.           where the afore-mentioned Clear code comes in.  As soon as we use
  2985.           entry 4094, we write out a (12-bit) Clear code.   (If we wait any
  2986.           longer to  write the  Clear code,  the decompressor  might try to
  2987.           interpret the  Clear code  as a 13-bit code.)  At this point, the
  2988.           compressor re-initializes the string table and starts writing out
  2989.           9-bit codes again.
  2990.           
  2991.           Note that  whenever you  write a code and add a table entry, _ is
  2992.           not left  empty.   It contains exactly one character.  Be careful
  2993.           not to  lose it  when you  write an end-of-table Clear code.  You
  2994.           can either write it out as a 12-bit code before writing the Clear
  2995.           code, in  which case  you will  want to  do it right after adding
  2996.           table entry  4093, or  after the  clear code  as  a  9-bit  code.
  2997.           Decompression gives the same result in either case.
  2998.           
  2999.           To make  things a  little simpler  for the  decompressor, we will
  3000.           require that  each strip  begins with a Clear code, and ends with
  3001.           an EndOfInformation code.
  3002.           
  3003.           Every LZW-compressed  strip must  begin on  a byte  boundary.  It
  3004.           need not  begin on  a word  boundary.   LZW compression codes are
  3005.           stored into  bytes in  high-to-low-order fashion, i.e., FillOrder
  3006.           is assumed  to be  1.  The compressed codes are written as bytes,
  3007.           not  words,  so  that  the  compressed  data  will  be  identical
  3008.           regardless of whether it is an _II_ or _MM_ file.
  3009.           
  3010.  
  3011.  
  3012.  
  3013.  
  3014.  
  3015.  
  3016.  
  3017.  
  3018.  
  3019.           TIFF 5.0                                          page 46
  3020.           TIFF 5.0                                          page 46
  3021.  
  3022.  
  3023.           Note that  the LZW string table is a continuously updated history
  3024.           of the  strings that  have been encountered in the data.  It thus
  3025.           reflects the characteristics of the data, providing a high degree
  3026.           of adaptability.
  3027.           
  3028.           
  3029.           LZW Decoding
  3030.           
  3031.           The procedure for decompression is a little more complicated, but
  3032.           still not too bad:
  3033.                     
  3034.                while ((Code = GetNextCode()) != EoiCode) {
  3035.                     if (Code == ClearCode) {
  3036.                          InitializeTable();
  3037.                          Code = GetNextCode();
  3038.                          if (Code == EoiCode)
  3039.                               break;
  3040.                          WriteString(StringFromCode(Code));
  3041.                          OldCode = Code;
  3042.                     }  /* end of ClearCode case */
  3043.           
  3044.                     else {
  3045.                          if (IsInTable(Code)) {
  3046.                               WriteString(StringFromCode(Code));
  3047.                               AddStringToTable(StringFromCode(OldCode)+Firs
  3048.           tChar(StringFromCode(Code)));
  3049.                               OldCode = Code;
  3050.                          } else {
  3051.                               OutString   =    StringFromCode(OldCode)    +
  3052.           FirstChar(StringFromCode(OldCode));
  3053.                               WriteString(OutString);
  3054.                               AddStringToTable(OutString);
  3055.                               OldCode = Code;
  3056.                          }
  3057.                     } /* end of not-ClearCode case */
  3058.                } /* end of while loop */
  3059.           
  3060.           The function  GetNextCode() retrieves the next code from the LZW-
  3061.           coded data.  It must keep track of bit boundaries.  It knows that
  3062.           the first code that it gets will be a 9-bit code.  We add a table
  3063.           entry each  time we get a code, so GetNextCode() must switch over
  3064.           to 10-bit codes as soon as string #511 is stored into the table.
  3065.           
  3066.           The function  StringFromCode() gets  the string associated with a
  3067.           particular code from the string table.
  3068.           
  3069.           The function  AddStringToTable() adds  a  string  to  the  string
  3070.           table.   The _+_  sign joining  the two  parts of the argument to
  3071.           AddStringToTable indicate string concatenation.
  3072.           
  3073.           StringFromCode() looks  up the  string associated  with  a  given
  3074.           code.
  3075.           
  3076.           WriteString() adds a string to the output stream.
  3077.  
  3078.  
  3079.  
  3080.  
  3081.  
  3082.  
  3083.  
  3084.  
  3085.  
  3086.           TIFF 5.0                                          page 47
  3087.           TIFF 5.0                                          page 47
  3088.  
  3089.  
  3090.           
  3091.           
  3092.           When SamplesPerPixel Is Greater Than 1
  3093.           
  3094.           We  have   so  far   described  the   compression  scheme  as  if
  3095.           SamplesPerPixel were  always 1,  as will  be  be  the  case  with
  3096.           palette color  and grayscale  images.  But what do we do with RGB
  3097.           image data?
  3098.           
  3099.           Tests on  our sample  images indicate  that the  LZW  compression
  3100.           ratio    is    nearly    identical    regardless    of    whether
  3101.           PlanarConfiguration=1 or  PlanarConfiguration=2, for  RGB images.
  3102.           So use  whichever configuration  you prefer,  and simply compress
  3103.           the bytes in the strip.
  3104.           
  3105.           It is  worth cautioning  that compression  ratios on our test RGB
  3106.           images were disappointing low: somewhere between 1.1 to 1 and 1.5
  3107.           to 1,  depending on the image.  Vendors are urged to do what they
  3108.           can to  remove as  much noise  from  their  images  as  possible.
  3109.           Preliminary tests  indicate that significantly better compression
  3110.           ratios are  possible with  less noisy  images.  Even something as
  3111.           simple as  zeroing out one or two least-significant bitplanes may
  3112.           be  quite   effective,  with   little  or  no  perceptible  image
  3113.           degradation.
  3114.           
  3115.           
  3116.           Implementation
  3117.           
  3118.           The exact  structure of  the string  table and the method used to
  3119.           determine if  a string  is already  in the table are probably the
  3120.           most significant  design decisions in the implementation of a LZW
  3121.           compressor and  decompressor.   Hashing has  been suggested  as a
  3122.           useful technique for the compressor.  We have chosen a tree based
  3123.           approach, with  good results.   The decompressor is actually more
  3124.           straightforward,  as   well  as   faster,  since   no  search  is
  3125.           involved_strings can be accessed directly by code value.
  3126.           
  3127.           
  3128.           Performance
  3129.           
  3130.           Many  people   do  not   realize  that  the  performance  of  any
  3131.           compression scheme  depends greatly  on the type of data to which
  3132.           it is  applied.   A scheme that works well on one data set may do
  3133.           poorly on the next.
  3134.           
  3135.           But since  we do  not want  to burden  the world  with  too  many
  3136.           compression schemes, an adaptive scheme such as LZW that performs
  3137.           quite well  on a wide range of images is very desirable.  LZW may
  3138.           not always  give optimal  compression ratios,  but  its  adaptive
  3139.           nature and relative simplicity seem to make it a good choice.
  3140.           
  3141.           Experiments thus  far indicate  that we  can  expect  compression
  3142.           ratios of  between 1.5  and 3.0  to 1  from LZW,  with no loss of
  3143.           data, on  continuous tone  grayscale scanned  images.  If we zero
  3144.  
  3145.  
  3146.  
  3147.  
  3148.  
  3149.  
  3150.  
  3151.  
  3152.  
  3153.           TIFF 5.0                                          page 48
  3154.           TIFF 5.0                                          page 48
  3155.  
  3156.  
  3157.           the least  significant one or two bitplanes of 8-bit data, higher
  3158.           ratios can be achieved.  These bitplanes often consist chiefly of
  3159.           noise, in  which case  little or no loss in image quality will be
  3160.           perceived.   Palette color  images created  in  a  paint  program
  3161.           generally compress  much  better  than  continuous  tone  scanned
  3162.           images, since paint images tend to be more repetitive.  It is not
  3163.           unusual to  achieve compression  ratios of 10 to 1 or better when
  3164.           using LZW on palette color paint images.
  3165.           
  3166.           By way  of comparison, PackBits, used in TIFF for black and white
  3167.           bilevel images, does not do well on color paint images, much less
  3168.           continuous tone  grayscale and  color images.  1.2 to 1 seemed to
  3169.           be about average for 4-bit images, and 8-bit images are worse.
  3170.           
  3171.           It has  been suggested that the CCITT 1D scheme could be used for
  3172.           continuous tone  images, by compressing each bitplane separately.
  3173.           No doubt  some  compression  could  be  achieved,  but  it  seems
  3174.           unlikely that  a scheme  based on a fixed table that is optimized
  3175.           for short  black runs  separated by  longer white runs would be a
  3176.           very good choice on any of the bitplanes.  It would do quite well
  3177.           on the  high-order bitplanes  (but so would a simpler scheme like
  3178.           PackBits), and  would do quite poorly on the low-order bitplanes.
  3179.           We believe  that the  compression ratios  would generally  not be
  3180.           very impressive, and the process would in addition be quite slow.
  3181.           Splitting  the  pixels  into  bitplanes  and  putting  them  back
  3182.           together is  somewhat expensive,  and the  coding is  also fairly
  3183.           slow when implemented in software.
  3184.           
  3185.           Another  approach   that  has  been  suggested  uses  uses  a  2D
  3186.           differencing step  following by  coding the  differences using  a
  3187.           fixed table  of variable-length codes.  This type of scheme works
  3188.           quite well  on many  8-bit  grayscale  images,  and  is  probably
  3189.           simpler  to  implement  than  LZW.    But  it  has  a  number  of
  3190.           disadvantages when  used on  a wide variety of images.  First, it
  3191.           is not  adaptive.   This makes  a big difference when compressing
  3192.           data such as 8-bit images that have been _sharpened_ using one of
  3193.           the standard  techniques.  Such images tend to get larger instead
  3194.           of smaller  when  compressed.    Another  disadvantage  of  these
  3195.           schemes is  that they  do not  do well  with a  wide range of bit
  3196.           depths.   The built-in  code table  has to  be  optimized  for  a
  3197.           particular bit depth in order to be effective.
  3198.           
  3199.           Finally,  we   should  mention   _lossy_   compression   schemes.
  3200.           Extensive research  has been  done in  the area of lossy, or non-
  3201.           information-preserving  image   compression.    These  techniques
  3202.           generally yield  much  higher  compression  ratios  than  can  be
  3203.           achieved  by   fully-reversible,   information-preserving   image
  3204.           compression  techniques   such  as   PackBits  and   LZW.    Some
  3205.           disadvantages:     many  of   the   lossy   techniques   are   so
  3206.           computationally expensive  that hardware  assists  are  required.
  3207.           Others  are  so  complicated  that  most  microcomputer  software
  3208.           vendors could  not afford either the expense of implementation or
  3209.           the increase  in  application  object  code  size.    Yet  others
  3210.  
  3211.  
  3212.  
  3213.  
  3214.  
  3215.  
  3216.  
  3217.  
  3218.  
  3219.  
  3220.           TIFF 5.0                                          page 49
  3221.           TIFF 5.0                                          page 49
  3222.  
  3223.  
  3224.           sacrifice enough  image  quality  to  make  them  unsuitable  for
  3225.           publishing use.
  3226.           
  3227.           In spite  of these  difficulties, we  believe that there will one
  3228.           day be  a standardized  lossy compression  scheme for  full color
  3229.           images  that  will  be  usable  for  publishing  applications  on
  3230.           microcomputers.   An International  Standards Organization group,
  3231.           ISO/IEC/JTC1/SC2/WG8, in cooperation with CCITT Study Group VIII,
  3232.           is hard at work on a scheme that might be appropriate.  We expect
  3233.           that a  future revision of TIFF will incorporate this scheme once
  3234.           it is  finalized, if it turns out to satisfy the needs of desktop
  3235.           publishers and  others in the microcomputer community.  This will
  3236.           augment, not replace, LZW as an approved TIFF compression scheme.
  3237.           LZW will  very likely  remain the  scheme of  choice for  Palette
  3238.           color images,  and perhaps  4-bit grayscale  images, and may well
  3239.           overtake CCITT 1D and PackBits for bilevel images.
  3240.           
  3241.           
  3242.           Future LZW Extensions
  3243.           
  3244.           Some images  compress better  using LZW  coding if they are first
  3245.           subjected to  a process  wherein each  pixel value is replaced by
  3246.           the  difference  between  the  pixel  and  the  preceding  pixel.
  3247.           Performing this  differencing in two dimensions helps some images
  3248.           even more.  However, many images do not compress better with this
  3249.           extra preprocessing,  and for a significant number of images, the
  3250.           compression ratio is actually worse.  We are therefore not making
  3251.           differencing an integral part of the TIFF LZW compression scheme.
  3252.           
  3253.           However,  it   is  possible   that  a   _prediction_  stage  like
  3254.           differencing may  exist which  is effective over a broad range of
  3255.           images.  If such a scheme is found, it may be incorporated in the
  3256.           next major TIFF revision.  If so, a new value will be defined for
  3257.           the new  _Predictor_ TIFF  tag.  Therefore, all TIFF readers that
  3258.           read LZW files must pay attention to the Predictor tag.  If it is
  3259.           1, which  is the  default case,  LZW  decompression  may  proceed
  3260.           safely.   If it  is not  1, and the reader does not recognize the
  3261.           specified prediction scheme, the reader should give up.
  3262.           
  3263.           
  3264.           Acknowledgements
  3265.           
  3266.           The original  LZW reference  has already  been given.  The use of
  3267.           ClearCode as a technique to handle overflow was borrowed from the
  3268.           compression scheme used by the Graphics Interchange Format (GIF),
  3269.           a small-color-paint-image-file  format used  by  CompuServe  that
  3270.           also is an adaptation of the LZW technique.  Joff Morgan and Eric
  3271.           Robinson of  Aldus were  each instrumental  in their  own way  in
  3272.           getting LZW off the ground.
  3273.           
  3274.  
  3275.  
  3276.  
  3277.  
  3278.  
  3279.  
  3280.  
  3281.  
  3282.  
  3283.  
  3284.  
  3285.  
  3286.  
  3287.           TIFF 5.0                                          page 50
  3288.           TIFF 5.0                                          page 50
  3289.  
  3290.  
  3291.           Appendix G: TIFF Classes
  3292.           
  3293.           
  3294.           Rationale
  3295.           
  3296.           TIFF was  designed to  make  life  easier  for  scanner  vendors,
  3297.           desktop publishing  software developers,  and users  of these two
  3298.           classes of products, by reducing the proliferation of proprietary
  3299.           scanned  image   formats.    It  has  succeeded  far  beyond  our
  3300.           expectations in  this respect.   But  we had  expected that  TIFF
  3301.           would be of interest to only a dozen or so scanner vendors (there
  3302.           weren_t any  more than  that in  1985), and  another dozen  or so
  3303.           desktop publishing  software vendors.   This  turned out  to be a
  3304.           gross underestimate.   The only problem with this sort of success
  3305.           is that  TIFF was  designed to  be powerful  and flexible, at the
  3306.           expense of  simplicity.   It takes  a fair  amount of  effort  to
  3307.           handle all  the options  currently defined  in this specification
  3308.           (probably no  application does  a  complete  job),  and  that  is
  3309.           currently the  only way  you can be sure that you will be able to
  3310.           import any  TIFF image,  since there are so many image-generating
  3311.           applications out there now.
  3312.           
  3313.           So here  is an attempt to channel some of the flexibility of TIFF
  3314.           into more  restrictive paths,  using what  we have learned in the
  3315.           past two  years about which options are the most useful.  Such an
  3316.           undertaking is  of course filled with fairly arbitrary decisions.
  3317.           But the  result is  that writers can more easily write files that
  3318.           will be  successfully read by a wide variety of applications, and
  3319.           readers can know when they can stop adding TIFF features.
  3320.           
  3321.           The price  we pay for TIFF Classes is some loss in the ability to
  3322.           adapt.   Once we  establish the requirements for a TIFF Class, we
  3323.           can never add new requirements, since old software would not know
  3324.           about these  new requirements.  (The best we can do at that point
  3325.           is establish new TIFF Classes.  But the problem with that is that
  3326.           we could quickly have too many TIFF Classes.)  So we must believe
  3327.           that we know what we are doing in establishing these Classes.  If
  3328.           we do not, any mistakes will be expensive.
  3329.           
  3330.           
  3331.           Overview
  3332.           
  3333.           Four TIFF Classes have been defined:
  3334.           
  3335.           ╤    Class B for bilevel (1-bit) images
  3336.           ╤    Class G for grayscale images
  3337.           ╤    Class P for palette color images
  3338.           ╤    Class R for RGB full color images
  3339.           
  3340.           To save  time and  space, we will usually say _TIFF B_, _TIFF G_,
  3341.           _TIFF P,_  and _TIFF R._  If we are talking about all four types,
  3342.           we may write _TIFF X._
  3343.           
  3344.  
  3345.  
  3346.  
  3347.  
  3348.  
  3349.  
  3350.  
  3351.  
  3352.  
  3353.  
  3354.           TIFF 5.0                                          page 51
  3355.           TIFF 5.0                                          page 51
  3356.  
  3357.  
  3358.           (Note to  fax people:   if  you are  interested in  a fax  TIFF F
  3359.           Class, please  get together  and decide  what should  be in  TIFF
  3360.           Class F  files.  Let us know if we can help in any way.  When you
  3361.           have decided,  send us  your results,  so that we can include the
  3362.           information here.)
  3363.           
  3364.           
  3365.           Core Requirements
  3366.           
  3367.           This section  describes requirements  that are common to all TIFF
  3368.           Class X images.
  3369.           
  3370.           General Requirements
  3371.           
  3372.           The following  are required  characteristics of  all TIFF Class X
  3373.           files.
  3374.           
  3375.           Where there are options, TIFF X writers can do whichever one they
  3376.           want, though  we will  often recommend  a particular  choice, but
  3377.           TIFF X  readers must  be able  to handle all of them.  Please pay
  3378.           close attention  to the  recommendations.  It is possible that at
  3379.           some point  in the future, new and even-simpler TIFF classes will
  3380.           be defined that include only recommended features.
  3381.           
  3382.           You will  need to  read at  least the first three sections of the
  3383.           main specification  in order  to fully  understand the  following
  3384.           discussion.
  3385.           
  3386.           Defaults.  TIFF X writers may, but are not required, to write out
  3387.           a field that has a default value, if the default value is the one
  3388.           desired.   TIFF X  readers must  be  prepared  to  handle  either
  3389.           situation.
  3390.           
  3391.           Other fields.   TIFF  X readers  must be  prepared  to  encounter
  3392.           fields other  than the  required fields  in TIFF X files.  TIFF X
  3393.           writers  are  allowed  to  write  fields  such  as  Make,  Model,
  3394.           DateTime, and so on, and TIFF X readers can certainly make use of
  3395.           such fields  if they  exist.   TIFF X  readers must not, however,
  3396.           refuse to read the file if such optional fields do not exist.
  3397.           
  3398.           _MM_ and  æIIÆ byte order.  TIFF X readers must be able to handle
  3399.           both byte  orders.    TIFF  writers  can  do  whichever  is  most
  3400.           convenient  or   efficient.     Images  are   crossing  the   IBM
  3401.           PC/Macintosh boundary  (and others  as well)  with a surprisingly
  3402.           high frequency.   We could force writers to all use the same byte
  3403.           order, but  preliminary evidence  indicates that  this will cause
  3404.           problems  when   we  start   seeing  greater-than-8-bit   images.
  3405.           Reversing bytes  while scanning could well slow down the scanning
  3406.           process enough  to cause  the scanning  mechanism to  stop, which
  3407.           tends to create image quality problems.
  3408.           
  3409.           Multiple subfiles.   TIFF X readers must be prepared for multiple
  3410.           images (i.e.,  subfiles) per  TIFF file,  although they  are  not
  3411.           required to do anything with any image after the first one.  TIFF
  3412.  
  3413.  
  3414.  
  3415.  
  3416.  
  3417.  
  3418.  
  3419.  
  3420.  
  3421.           TIFF 5.0                                          page 52
  3422.           TIFF 5.0                                          page 52
  3423.  
  3424.  
  3425.           X writers  must be  sure to write a long word of 0 after the last
  3426.           IFD (this is the standard way of signalling that this IFD was the
  3427.           last one) as indicated in the TIFF structure discussion.
  3428.           
  3429.           If a  TIFF X  writer writes multiple subfiles, the first one must
  3430.           be the  full resolution  image.   Subsequent subimages,  such  as
  3431.           reduced resolution  images and  transparency masks, may be in any
  3432.           order in  the TIFF  file.   If a reader wants to make use of such
  3433.           subimages, it  will have to scan the IFDÆs before deciding how to
  3434.           proceed.
  3435.           
  3436.           TIFF X  Editors.   Editors, applications  that modify TIFF files,
  3437.           have a few additional requirements.
  3438.           
  3439.           TIFF editors  must be  especially careful  about subfiles.   If a
  3440.           TIFF editor  edits a full-resolution subfile, but does not update
  3441.           an accompanying  reduced-resolution subfile,  a reader  that uses
  3442.           the reduced-resolution  subfile for  screen display  will display
  3443.           the wrong  thing.   So TIFF  editors must  either  create  a  new
  3444.           reduced-resolution subfile  when  they  alter  a  full-resolution
  3445.           subfile, or  else they  must simply delete any subfiles that they
  3446.           aren_t prepared to deal with.
  3447.           
  3448.           A similar  situation arises with the fields themselves.  A TIFF X
  3449.           editor need  only worry  about the  TIFF X  required fields.   In
  3450.           particular, it  is unnecessary,  and probably  dangerous, for  an
  3451.           editor to  copy fields  that it does not understand.  It may have
  3452.           altered the  file in  a way that is incompatible with the unknown
  3453.           fields.
  3454.           
  3455.           
  3456.           Required Fields
  3457.           
  3458.           NewSubfileType.  LONG.  Recommended but not required.
  3459.           
  3460.           ImageWidth.   SHORT or  LONG.   (That is, both _SHORT_ and _LONG_
  3461.           TIFF data  types are  allowed, and  must be  handled properly  by
  3462.           readers.   TIFF writers  can use either.)  TIFF X readers are not
  3463.           required to  read arbitrarily  large files however.  Some readers
  3464.           will give  up if the entire image cannot fit in available memory.
  3465.           (In such cases the reader should inform the user of the nature of
  3466.           the problem.)   Others  will  probably  not  be  able  to  handle
  3467.           ImageWidth greater  than 65535.   Recommendation: use LONG, since
  3468.           resolutions seem to keep going up.
  3469.           
  3470.           ImageLength.  SHORT or LONG.  Recommendation: use  LONG.
  3471.           
  3472.           RowsPerStrip.  SHORT or LONG.  Readers must be able to handle any
  3473.           value between  1 and  2**32-1.   However, some readers may try to
  3474.           read an  entire strip  into memory  at one  time, so  that if the
  3475.           entire image is one strip, the application may run out of memory.
  3476.           Recommendation 1:   Set  RowsPerStrip such  that the size of each
  3477.           strip is  about 8K  bytes.   Do this  even for uncompressed data,
  3478.           since it  is easy  for a  writer and  makes  things  simpler  for
  3479.  
  3480.  
  3481.  
  3482.  
  3483.  
  3484.  
  3485.  
  3486.  
  3487.  
  3488.           TIFF 5.0                                          page 53
  3489.           TIFF 5.0                                          page 53
  3490.  
  3491.  
  3492.           readers.  (Note:  extremely wide, high-resolution images may have
  3493.           rows larger  than 8K  bytes; in this case, RowsPerStrip should be
  3494.           1,  and   the  strip  will  just  have  to  be  larger  than  8K.
  3495.           Recommendation 2: use LONG.
  3496.           
  3497.           StripOffsets.   SHORT or  LONG.  As explained in the main part of
  3498.           the  specification,   the  number   of  StripOffsets  depends  on
  3499.           RowsPerStrip and  ImageLength.  Recommendation:  always use LONG.
  3500.           (LONG must, of course, be used if the file is more than 64K bytes
  3501.           in length.)
  3502.           
  3503.           StripByteCounts.   SHORT or  LONG.   Many existing TIFF images do
  3504.           not contain StripByteCounts, because, in a strict sense, they are
  3505.           unnecessary.   It is  possible to  write an efficient TIFF reader
  3506.           that does  not need  to know  in advance  the  exact  size  of  a
  3507.           compressed strip.   But  it does  make things  considerably  more
  3508.           complicated, so  we will require StripByteCounts in TIFF X files.
  3509.           Recommendation:   use SHORT,  since strips are not supposed to be
  3510.           very large.
  3511.           
  3512.           XResolution, YResolution.   RATIONAL.   Note  that the  X  and  Y
  3513.           resolutions may  be unequal.   A  TIFF X  reader must  be able to
  3514.           handle this  case.   TIFF X pixel-editors will typically not care
  3515.           about the  resolution,  but  applications  such  as  page  layout
  3516.           programs will.
  3517.           
  3518.           ResolutionUnit.   SHORT.   TIFF X  readers must  be  prepared  to
  3519.           handle all three values for ResolutionUnit.
  3520.           
  3521.           
  3522.           TIFF Class B - Bilevel
  3523.           
  3524.           Required (in addition to the above core requirements)
  3525.           
  3526.           The following fields and values are required for TIFF B files, in
  3527.           addition to  the fields  required for  all  TIFF  X  images  (see
  3528.           above).
  3529.           
  3530.           SamplesPerPixel =  1.   SHORT.   (Since this  is the default, the
  3531.           field need  not be  present.   The same  thing  holds  for  other
  3532.           required TIFF X fields that have defaults.)
  3533.           
  3534.           BitsPerSample = 1.  SHORT.
  3535.           
  3536.           Compression = 1, 2 (CCITT 1D), or 32773 (PackBits).  SHORT.  TIFF
  3537.           B readers  must handle all three.  Recommendation:  use PackBits.
  3538.           It  is  simple,  effective,  fast,  and  has  a  good  worst-case
  3539.           behavior.    CCITT  1D  is  definitely  more  effective  in  some
  3540.           situations, such as scanning a page of body text, but is tough to
  3541.           implement and  test, fairly  slow,  and  has  a  poor  worst-case
  3542.           behavior.   Besides, scanning a page of 12 point text is not very
  3543.           useful for  publishing applications,  unless the  image  data  is
  3544.           turned into  ASCII text  via OCR  software, which  is outside the
  3545.           scope of TIFF.
  3546.  
  3547.  
  3548.  
  3549.  
  3550.  
  3551.  
  3552.  
  3553.  
  3554.  
  3555.           TIFF 5.0                                          page 54
  3556.           TIFF 5.0                                          page 54
  3557.  
  3558.  
  3559.           
  3560.           PhotometricInterpretation = 0 or 1.  SHORT.
  3561.           A Sample TIFF B Image
  3562.           
  3563.           Offset         Value
  3564.           (hex)     Name (mostly hex)
  3565.           
  3566.           Header:
  3567.           0000 Byte Order     4D4D
  3568.           0002 Version   002A
  3569.           0004 1st IFD pointer     00000014
  3570.           
  3571.           IFD:
  3572.           0014 Entry Count    000D
  3573.           0016 NewSubfileType 00FE 0004 00000001  00000000
  3574.           0022 ImageWidth     0100 0004 00000001  000007D0
  3575.           002E ImageLength    0101 0004 00000001  00000BB8
  3576.           003A Compression    0103 0003 00000001  8005 0000
  3577.           0046 PhotometricInterpretation     0106 0003 00000001  0001 0000
  3578.           0052 StripOffsets   0111 0004 000000BC  000000B6
  3579.           005E RowsPerStrip   0116 0004 00000001  00000010
  3580.           006A StripByteCounts     0117 0003 000000BC  000003A6
  3581.           0076 XResolution    011A 0005 00000001  00000696
  3582.           0082 YResolution    011B 0005 00000001  0000069E
  3583.           008E Software  0131 0002 0000000E  000006A6
  3584.           009A DateTime  0132 0002 00000014  000006B6
  3585.           00A6 Next IFD pointer    00000000
  3586.           
  3587.           Fields pointed to by the tags:
  3588.           00B6 StripOffsets   Offset0, Offset1, ... Offset187
  3589.           03A6 StripByteCounts     Count0, Count1, ... Count187
  3590.           0696 XResolution    0000012C 00000001
  3591.           069E YResolution    0000012C 00000001
  3592.           06A6 Software  "PageMaker 3.0"
  3593.           06B6 DateTime  "1988:02:18 13:59:59"
  3594.           
  3595.           
  3596.           Image Data:
  3597.           00000700  Compressed data for strip 10
  3598.           xxxxxxxx  Compressed data for strip 179
  3599.           xxxxxxxx  Compressed data for strip 53
  3600.           xxxxxxxx  Compressed data for strip 160
  3601.           .
  3602.           .
  3603.           .
  3604.           
  3605.           End of example
  3606.           
  3607.           Comments on the TIFF B example
  3608.           
  3609.           1.   The IFD  in our example starts at position hex 14.  It could
  3610.           have been  anywhere in  the file  as long as the position is even
  3611.           and greater  than or equal to 8, since the TIFF header is 8 bytes
  3612.           long and must be the first thing in a TIFF file.
  3613.  
  3614.  
  3615.  
  3616.  
  3617.  
  3618.  
  3619.  
  3620.  
  3621.  
  3622.           TIFF 5.0                                          page 55
  3623.           TIFF 5.0                                          page 55
  3624.  
  3625.  
  3626.           
  3627.           2.   With 16 rows per strip, we have 188 strips in all.
  3628.           
  3629.           3.   The example  uses a  number  of  optional  fields,  such  as
  3630.           DateTime.   TIFF X  readers must safely skip over these fields if
  3631.           they do not want to use the information.  And TIFF X readers must
  3632.           not require that such fields be present.
  3633.           
  3634.           4.   Just for  fun, our example has highly fragmented image data;
  3635.           the strips  of our  image are  not even in sequential order.  The
  3636.           point is  that strip  offsets must  not be ignored.  Never assume
  3637.           that strip  N+1 follows  strip N.    Incidentally,  there  is  no
  3638.           requirement that  the image  data follows  the  IFD  information.
  3639.           Just the follow the pointers, whether they be IFD pointers, field
  3640.           pointers, or Strip Offsets.
  3641.           
  3642.           
  3643.           
  3644.           TIFF Class G - Grayscale
  3645.           
  3646.           Required (in addition to the above core requirements)
  3647.           
  3648.           SamplesPerPixel = 1.  SHORT.
  3649.           
  3650.           BitsPerSample =  4,  8.    SHORT.    There  seems  to  be  little
  3651.           justification for  working with grayscale images shallower than 4
  3652.           bits, and 5-bit , 6-bit, and 7-bit images can easily be stored as
  3653.           8-bit images, as long as you can compress the _unused_ bit planes
  3654.           without penalty.  And we can do just that with LZW (Compression =
  3655.           5.)
  3656.           
  3657.           Compression = 1 or 5 (LZW).  SHORT.  Recommendation: use 5, since
  3658.           LZW decompression is turning out to be quite fast.
  3659.           
  3660.           PhotometricInterpretation = 0 or 1.  SHORT.   Recommendation: use
  3661.           1, due  to popular  user interfaces  for adjusting brightness and
  3662.           contrast.
  3663.           
  3664.           
  3665.           
  3666.           TIFF Class P - Palette Color
  3667.           
  3668.           Required (in addition to the above core requirements)
  3669.           
  3670.           SamplesPerPixel = 1.  SHORT.  We use each pixel value as an index
  3671.           into all three color tables in ColorMap.
  3672.           
  3673.           BitsPerSample =  1,2,3,4,5,6,7, or 8.  SHORT.  1,2,3,4, and 8 are
  3674.           probably the  most common,  but as long as we are doing that, the
  3675.           rest come pretty much for free.
  3676.           
  3677.           Compression = 1 or 5.  SHORT.
  3678.           
  3679.           PhotometricInterpretation = 3 (Palette Color).  SHORT.
  3680.  
  3681.  
  3682.  
  3683.  
  3684.  
  3685.  
  3686.  
  3687.  
  3688.  
  3689.           TIFF 5.0                                          page 56
  3690.           TIFF 5.0                                          page 56
  3691.  
  3692.  
  3693.           
  3694.           ColorMap.  SHORT.
  3695.           
  3696.           Note that  bilevel and  grayscale images  can be  represented  as
  3697.           special cases  of palette  color images.  As soon as enough major
  3698.           applications support  palette color  images, we may want to start
  3699.           getting rid  of  distinctions  between  bilevel,  grayscale,  and
  3700.           palette color images.
  3701.           
  3702.           
  3703.           TIFF Class R - RGB Full Color
  3704.           
  3705.           Required (in addition to the above Core Requirements)
  3706.           
  3707.           SamplesPerPixel = 3.  SHORT.  One sample each for Red, Green, and
  3708.           Blue.
  3709.           
  3710.           BitsPerSample =  8,8,8.   SHORT.  Shallower samples can easily be
  3711.           stored as 8-bit samples with no penalty if the data is compressed
  3712.           with LZW.  And evidence to date indicates that images deeper than
  3713.           8 bits  per sample are not worth the extra work, even in the most
  3714.           demanding publishing applications.
  3715.           
  3716.           PlanarConfiguration = 1 or 2.  SHORT.  Recommendation:  use 1.
  3717.           
  3718.           Compression = 1 or 5.  SHORT.
  3719.           
  3720.           PhotometricInterpretation = 2 (RGB).  SHORT.
  3721.           
  3722.           Recommended
  3723.           
  3724.           Recommended for  TIFF Class  R, but not required, are the new (as
  3725.           of Revision 5.0) colorimetric information tags.  See Appendix H.
  3726.           
  3727.           
  3728.           Conformance and User Interface
  3729.           
  3730.           Applications that  write valid  TIFF X files should include _TIFF
  3731.           B_ and/or  _TIFF G_  and/or _TIFF  P_ and/or  _TIFF R_  and/or in
  3732.           their product  spec sheets, if they can write the respective TIFF
  3733.           Class X  files.   If your  application writes  all four  of these
  3734.           types, you  may wish to write it as _TIFF B,G,P,R._  Of course, a
  3735.           term like  _TIFF B,_  while fine  for  communicating  with  other
  3736.           vendors, will  not convey much information to a typical user.  In
  3737.           this case,  a  phrase  such  as  _Standard  TIFF  Black-and-White
  3738.           Scanned Images_ might be better.
  3739.           
  3740.           The same  terminology guidelines  apply to applications that read
  3741.           TIFF Class X files.
  3742.           
  3743.           If your  application reads more kinds of files than it writes, or
  3744.           vice versa,  it would  be a  good idea  to make that clear to the
  3745.           buyer.   For example, if your application reads TIFF B and TIFF G
  3746.  
  3747.  
  3748.  
  3749.  
  3750.  
  3751.  
  3752.  
  3753.  
  3754.  
  3755.  
  3756.           TIFF 5.0                                          page 57
  3757.           TIFF 5.0                                          page 57
  3758.  
  3759.  
  3760.           files, but writes only TIFF G files, you should write it that way
  3761.           in the spec sheet.
  3762.           
  3763.  
  3764.  
  3765.  
  3766.  
  3767.  
  3768.  
  3769.  
  3770.  
  3771.  
  3772.  
  3773.  
  3774.  
  3775.  
  3776.  
  3777.  
  3778.  
  3779.  
  3780.  
  3781.  
  3782.  
  3783.  
  3784.  
  3785.  
  3786.  
  3787.  
  3788.  
  3789.  
  3790.  
  3791.  
  3792.  
  3793.  
  3794.  
  3795.  
  3796.  
  3797.  
  3798.  
  3799.  
  3800.  
  3801.  
  3802.  
  3803.  
  3804.  
  3805.  
  3806.  
  3807.  
  3808.  
  3809.  
  3810.  
  3811.  
  3812.  
  3813.  
  3814.  
  3815.  
  3816.  
  3817.  
  3818.  
  3819.  
  3820.  
  3821.  
  3822.  
  3823.           TIFF 5.0                                          page 58
  3824.           TIFF 5.0                                          page 58
  3825.  
  3826.  
  3827.           Appendix H: Image Colorimetry Information
  3828.           
  3829.           Chris Sears
  3830.           210 Lake Street
  3831.           San Francisco, CA 94118
  3832.           
  3833.           June 4, 1988
  3834.           Revised August 8, 1988
  3835.           
  3836.           
  3837.           I. Introduction
  3838.           
  3839.           Our goal is to accurately reproduce a color image using different
  3840.           devices.   Accuracy requires  techniques  of  measurement  and  a
  3841.           standard  of   comparison.     Different  devices   imply  device
  3842.           independence.   Colorimetry provides the framework to solve these
  3843.           problems.  When an image has a complete colorimetric description,
  3844.           in principle  it  can  be  reproduced  identically  on  different
  3845.           monitors and using different media, such as offset lithography.
  3846.           
  3847.           The colorimetry  data is  specified when  the image is created or
  3848.           changed.   A scanned image has colorimetry data derived from  the
  3849.           filters and  light sources  of the  scanner and a synthetic image
  3850.           has colorimetry  data corresponding to the monitor used to create
  3851.           it or  the monitor model of the rendering environment.  This data
  3852.           is used  to map  an input  image to  the markings  or colors of a
  3853.           particular output device.
  3854.           
  3855.           Section II  describes various  standards organizations  and their
  3856.           work in color.
  3857.           Section III describes our motivation for seeking these tags.
  3858.           Section IV describes our goals of reproduction.
  3859.           Sections V, VI and VII introduce the colorimetry tags.
  3860.           Section VIII specifies the tags themselves.
  3861.           Section IX describes the defaults.
  3862.           Section X discusses the limitations and some of the other issues.
  3863.           Section XI provides a few references.
  3864.           
  3865.           
  3866.           II. Related Standards
  3867.           
  3868.           TIFF is  a general  standard for describing image data.  It would
  3869.           be foolish  for us  to change  TIFF in  a way  that did not match
  3870.           existing industry  and international  standards.   Therefore,  we
  3871.           have taken  pains to  note in the discussion below the efforts of
  3872.           various standards organizations and select defaults from the work
  3873.           of these organizations.
  3874.           
  3875.           CIE  (Commission Internationale de lÆEclairage)  The basis of the
  3876.           colorimetry information  is the  CIE 1931  Standard Observer [3].
  3877.           While other color models could be supported [1] [4], CIE 1931 XYZ
  3878.           is the  international standard  accepted  across  industries  for
  3879.           specifying  color   and  CIE  xyY  is  the  chromaticity  diagram
  3880.           associated with CIE 1931 XYZ tristimulus values.
  3881.  
  3882.  
  3883.  
  3884.  
  3885.  
  3886.  
  3887.  
  3888.  
  3889.  
  3890.           TIFF 5.0                                          page 59
  3891.           TIFF 5.0                                          page 59
  3892.  
  3893.  
  3894.           
  3895.           NTSC (National Television  System Committee)  NTSC is of interest
  3896.           primarily  for   historical  reasons  and  its  use  in  encoding
  3897.           television data.   Manufacturing  standards for monitors have for
  3898.           some time  drifted significantly  from the  1953 NTSC colorimetry
  3899.           specification.
  3900.           
  3901.           SMPTE     (Society of  Motion Picture  and Television  Engineers)
  3902.           Most of  the work  by NTSC  has been  largely subsumed  by SMPTE.
  3903.           This organization  has a  set of  standards  called  "Recommended
  3904.           Practices" that  apply to  various technical  aspects of film and
  3905.           television production [5] [6].
  3906.           
  3907.           ISO  (International  Standards  Organization)    ISO  has  become
  3908.           involved in  color standards  through work on a color addendum to
  3909.           "Office Document Architecture (ODA) and Interchange Format" [7].
  3910.           
  3911.           ANSI (American  National   Standards  Institute)    ANSI  is  the
  3912.           American representative to ISO .
  3913.           
  3914.           
  3915.           III. Motivation
  3916.           
  3917.           Our motivation  for defining  these tags  stems from our research
  3918.           and  development  in  color  separation  technology.    With  the
  3919.           information described here and the RGB pixel data, we have all of
  3920.           the  information  necessary  for  generating  high-quality  color
  3921.           separations.  We could supply the colorimetry information outside
  3922.           of the  image  file.    But  since  TIFF  provides  a  convenient
  3923.           mechanism for  bundling all  of the  relevant  information  in  a
  3924.           single place,  tags are  defined to  describe this information in
  3925.           color TIFF files.
  3926.           
  3927.           A color  image rendered  with incorrect  colorimetry  information
  3928.           looks different  from the original.  One of our early test images
  3929.           has an artifact in it where the image was scanned with one set of
  3930.           primaries and  color ramps  were  overlaid  on  top  of  it  with
  3931.           different primaries.  The blue ramp looked purple when we printed
  3932.           it. Using incorrect gamma tables or white points can also lead to
  3933.           distorted images.  The best way to avoid these kinds of errors is
  3934.           to allow  the creator  of an  image  to  supply  the  colorimetry
  3935.           information along with the RGB values [1] [2].
  3936.           
  3937.           The purpose  of the  colorimetry data  is to  allow a  projective
  3938.           transformation from the primaries and white point of the image to
  3939.           the primaries  and white  point of  the rendering  media.   Gamma
  3940.           reflects the non-linear transfer gradient of real media.
  3941.           
  3942.           
  3943.           IV. Colorimetric Color Reproduction
  3944.           
  3945.           Earlier we  said that given the proper colorimetric data an image
  3946.           could be  rendered identically  using  two  different  calibrated
  3947.           devices.   By identical,  we mean  colorimetric reproduction [9].
  3948.  
  3949.  
  3950.  
  3951.  
  3952.  
  3953.  
  3954.  
  3955.  
  3956.  
  3957.           TIFF 5.0                                          page 60
  3958.           TIFF 5.0                                          page 60
  3959.  
  3960.  
  3961.           Specifically, the  chromaticities  match  and  the  luminance  is
  3962.           scaled to correspond to the luminance range of the output device.
  3963.           Because of this, we only need the chromaticity coordinates of the
  3964.           white point  and primaries.   The absolute luminance is arbitrary
  3965.           and unnecessary.
  3966.           
  3967.           
  3968.           V. White Point
  3969.           
  3970.           In TIFF 4.0, the white point was specified as D65.  This appendix
  3971.           allocates a  separate tag  for describing the white point and D65
  3972.           is the logical default since it is the SMPTE standard [6].
  3973.           
  3974.           The white  point is  defined  colorimetrically  in  the  CIE  xyY
  3975.           chromaticity diagram.   While  it is  rare for monitors to differ
  3976.           from D65,  scanned images  often  have  different  white  points.
  3977.           Rendered images  can have  arbitrary white  points.   The graphic
  3978.           arts use D50 as the standard viewing light source [8].
  3979.           
  3980.           
  3981.           VI. Primary Chromaticities
  3982.           
  3983.           In TIFF  4.0, the  primary color  chromaticities matched the NTSC
  3984.           specification.  With the wide variety of color scanners, monitors
  3985.           and renderers,  TIFF needs  a mechanism for accurately describing
  3986.           the chromaticities  of the  primary colors.   We use SMPTE as the
  3987.           default chromaticity  since conventional  monitors are  closer to
  3988.           SMPTE and  some monitors  (Conrac 6545)  are manufactured  to the
  3989.           SMPTE specifications.   We  donÆt use the NTSC chromaticities and
  3990.           white point  because present day monitors donÆt use them and must
  3991.           be _matrixed_ to approximate them.
  3992.           
  3993.           As an  example, the primary color chromaticities used by the Sony
  3994.           Trinatron differ  from those  recommended by  SMPTE.  In general,
  3995.           since  real  monitors  vary  from  the  industry  standards,  the
  3996.           chromaticities of  primaries are described in the CIE xyY system.
  3997.           This  allows   a  reproduction   system  to  compensate  for  the
  3998.           differences.
  3999.           
  4000.           
  4001.           VII. Color Response Curves
  4002.           
  4003.           This tag  defines three  color response curves, one each for red,
  4004.           green, and blue color information.  The width of each entry is 16
  4005.           bits, as  implied by  the type  SHORT.   The minimum intensity is
  4006.           represented by 0 and the maximum by 65535.  For example, black is
  4007.           represented by  0,0,0 and  white by  65535, 65535,  65535.    The
  4008.           length of  each curve is 2**BitsPerSample.  A ColorResponseCurves
  4009.           field for RGB data where each of the samples is 8 bits deep would
  4010.           have 3*256  entries.   The 256  red  entries  would  come  first,
  4011.           followed by 256 green entries, followed by 256 blue entries.
  4012.           
  4013.           The purpose  of the  ColorResponseCurves field  is to  act  as  a
  4014.           lookup table  mapping sample values to specific intensity values,
  4015.  
  4016.  
  4017.  
  4018.  
  4019.  
  4020.  
  4021.  
  4022.  
  4023.  
  4024.           TIFF 5.0                                          page 61
  4025.           TIFF 5.0                                          page 61
  4026.  
  4027.  
  4028.           so that  an image  created on  one system  can  be  displayed  on
  4029.           another   with   minimal   loss   of   color   fidelity.      The
  4030.           ColorResponseCurves field thus describes the _gamma_ of an image,
  4031.           so that  a TIFF  reader on another system can compensate for both
  4032.           the image gamma and the gamma of the reading system.
  4033.           
  4034.           Gamma is  a term that relates to the typically nonlinear response
  4035.           of most  display devices,  including monitors.   In  most display
  4036.           systems, the  voltage applied to the CRT is directly proportional
  4037.           to the  value of  the red,  green, or  blue sample.  However, the
  4038.           resulting luminance  emitted by  the  phosphor  is  not  directly
  4039.           proportional to  the voltage.   This relationship is approximated
  4040.           in most displays by
  4041.           
  4042.                luminance = voltage ** gamma
  4043.           
  4044.           The NTSC  standard gamma  of 2.2 adequately describes most common
  4045.           video systems.  The standard  gamma of  2.2 implies a dim viewing
  4046.           surround.   (We know of no SMPTE recommended practice for gamma.)
  4047.           The following example uses an 8 bit sample with value of 127.
  4048.           
  4049.                voltage = 127 / 255 = 0.4980
  4050.                luminance = 0.4980 ** 2.2 = 0.2157
  4051.           
  4052.           In the  examples below,  we only  consider a  single primary  and
  4053.           therefore only a single curve.  The same analysis applies to each
  4054.           of the  red, green,  and blue  primaries and  curves.   Also, and
  4055.           without loss  of generality,  we assume that there is no hardware
  4056.           color map, so that we must alter the pixel values themselves.  If
  4057.           there is  a color  map, the  manipulations can be done on the map
  4058.           instead of on the pixels.
  4059.           
  4060.           If no  ColorResponseCurves field  exists in  a color  image,  the
  4061.           reader should  assume a  gamma of  2.2 for each of the primaries.
  4062.           This default curve can be generated with the following C code:
  4063.           
  4064.                ValuesPerSample = 1 << BitsPerSample;
  4065.                for (curve[0] = 0, i = 1; i < ValuesPerSample; i++)
  4066.                     curve[i] =  floor (pow  (i /  (ValuesPerSample -  1.0),
  4067.           2.2) * 65535.0 + .5);
  4068.           
  4069.           The displaying  or rendering  application can know its own gamma,
  4070.           which we  will call  the _destination  gamma._   (An uncalibrated
  4071.           system can usually assume that its gamma is 2.2 without going too
  4072.           far  wrong.)     Using   this  information  the  application  can
  4073.           compensate for the gamma of the image, as we shall see below.
  4074.           
  4075.           If  the  source  and  destination  systems  are  both  adequately
  4076.           described  by   a  gamma  of  2.2,  the  writer  would  omit  the
  4077.           ColorResponseCurves field,  and the  reader can  simply read  the
  4078.           image directly into the frame buffer.  If a writer writes out the
  4079.           ColorResponseCurves field,  then a  reader must  assume that  the
  4080.           gammas  differ.    A  reader  must  then  perform  the  following
  4081.           computation on each sample in the image:
  4082.  
  4083.  
  4084.  
  4085.  
  4086.  
  4087.  
  4088.  
  4089.  
  4090.  
  4091.           TIFF 5.0                                          page 62
  4092.           TIFF 5.0                                          page 62
  4093.  
  4094.  
  4095.           
  4096.                NewSampleValue  =   floor  (pow   (curve[OldSampleValue]   /
  4097.           65535.0, 1.0 / DestinationGamma) *
  4098.                  (ValuesPerSample - 1.0) + .5);
  4099.           
  4100.           Of course,  if the _gamma_ of the destination system is not well-
  4101.           approximated with  an exponential  function, an  arbitrary  table
  4102.           lookup may  be used  in place  of raising  the  value  to  1.0  /
  4103.           DestinationGamma.
  4104.           
  4105.           Leave out  ColorResponseCurves if  using the default gamma.  This
  4106.           saves about  1.5K in  the  most  common  case,  and,  after  all,
  4107.           omission is the better part of compression.
  4108.           
  4109.           Do not  use this  field to  store frame  buffer color  maps.  Use
  4110.           instead   the    ColorMap   field.       Note,    however,   that
  4111.           ColorResponseCurves may  be used  to refine  the information in a
  4112.           ColorMap if desired.
  4113.           
  4114.           The above  examples assume  that a  single parameter gamma system
  4115.           adequately approximates the response characteristics of the image
  4116.           source and  destination systems.   This will usually be true, but
  4117.           our use  of a table instead of a single gamma parameter gives the
  4118.           flexibility  to  describe  more  complex  relationships,  without
  4119.           requiring additional computation or complexity.
  4120.           
  4121.           
  4122.           VIII. New Tags and Changes
  4123.           The following tags should be placed in the "Basic Fields" section
  4124.           of
  4125.           the TIFF specification:
  4126.           
  4127.           White Point
  4128.           Tag  = 318 (13E)
  4129.           Type = RATIONAL
  4130.           N    = 2
  4131.           
  4132.           The white  point of the image.  Note that this value is described
  4133.           using  the  1931  CIE  xyY  chromaticity  diagram  and  only  the
  4134.           chromaticity is  specified.  The luminance component is arbitrary
  4135.           and not  specified.   This can correspond to the white point of a
  4136.           monitor that  the image  was painted  on,  the  filter  set/light
  4137.           source combination  of a  scanner, or  to the  white point of the
  4138.           illumination model of a rendering package.
  4139.           
  4140.           Default is the SMPTE white point, D65:  x = 0.313, y = 0.329.
  4141.           
  4142.           The ordering is x, y.
  4143.           
  4144.           
  4145.           PrimaryChromaticities
  4146.           Tag  = 319 (13F)
  4147.           Type = RATIONAL
  4148.           N    = 6
  4149.  
  4150.  
  4151.  
  4152.  
  4153.  
  4154.  
  4155.  
  4156.  
  4157.  
  4158.           TIFF 5.0                                          page 63
  4159.           TIFF 5.0                                          page 63
  4160.  
  4161.  
  4162.           
  4163.           The primary  color chromaticities.   Note  that these  values are
  4164.           described using  the 1931  CIE xyY  chromaticity diagram and only
  4165.           the chromaticities  are  specified.    For  paint  images,  these
  4166.           represent the  chromaticities of  the  monitor  and  for  scanned
  4167.           images  they   are  derived  from  the  filter  set/light  source
  4168.           combination of a scanner.
  4169.           
  4170.           Default is the SMPTE primary color chromaticities:
  4171.           
  4172.                Red: x = 0.635 y = 0.340
  4173.                Green:    x = 0.305 y = 0.595
  4174.                Blue:     x = 0.155 y = 0.070
  4175.           
  4176.           The ordering is red x, red y, green x, green y, blue x, blue y.
  4177.           
  4178.           Color Response Curves
  4179.           
  4180.           Default for  ColorResponseCurves represents  curves corresponding
  4181.           to the NTSC standard gamma of 2.2.
  4182.           
  4183.           
  4184.           IX. Defaults
  4185.           
  4186.           The defaults  used by  TIFF reflect industry standards.  Both the
  4187.           WhitePoint and  PrimaryChromaticities tags have defaults that are
  4188.           promoted  by   SMPTE  .     In  addition,  the  default  for  the
  4189.           ColorResponseCurves tag matches the NTSC specification of a gamma
  4190.           of 2.2.
  4191.           
  4192.           The purpose  of these  defaults is to allow reasonable results in
  4193.           the absence  of  accurate  colorimetry  data.    An  uncalibrated
  4194.           scanner or  paint system  produces an  image  that  be  displayed
  4195.           identically, though  probably incorrectly  on two  different  but
  4196.           calibrated systems.   This is better then the uncertain situation
  4197.           where the  image might  be rendered  differently on two different
  4198.           but calibrated systems.
  4199.           
  4200.           
  4201.           X. Limitations and Issues
  4202.           
  4203.           This section  discusses several  of the  limitations  and  issues
  4204.           involved in colorimetric reproduction.
  4205.           
  4206.           Scope of Usefulness
  4207.           
  4208.           For many  purposes the  data recommended  here is unnecessary and
  4209.           can be omitted.  For presentation graphics where there are only a
  4210.           few colors,  being able  to tell  red from green is probably good
  4211.           enough.   In this  case the  tags can  be ignored and there is no
  4212.           overhead.   In more  demanding color  reproduction  environments,
  4213.           this data  allows images to be described device independently and
  4214.           at small cost.
  4215.           
  4216.  
  4217.  
  4218.  
  4219.  
  4220.  
  4221.  
  4222.  
  4223.  
  4224.  
  4225.           TIFF 5.0                                          page 64
  4226.           TIFF 5.0                                          page 64
  4227.  
  4228.  
  4229.           User Burdens
  4230.           
  4231.           The data we recommend isnÆt a user burden; it is really a systems
  4232.           issue.   It allows  a systems  solution but  doesnÆt require user
  4233.           intercession.   Calibration however  is a  separate issue.  It is
  4234.           likely to involve the user.
  4235.           
  4236.           Resolution Versus Fidelity
  4237.           
  4238.           Some manufacturers  supply greater than 24 bits of resolution for
  4239.           color specification.   The  purpose of  this is  either to  avoid
  4240.           artifacts such  as contouring  in the shadows or in some cases to
  4241.           be more  specific or  device independent  about the  color.  Both
  4242.           reasons can  be misguided.   Other, less expensive techniques can
  4243.           be used  to prevent artifacts, such as deeper color maps.  As for
  4244.           accuracy, fidelity is more important than precision.
  4245.           
  4246.           Colorimetric Color Reproduction
  4247.           
  4248.           There are other choices for objectives of color reproduction [9].
  4249.           Spectral color  reproduction is a stronger condition and most are
  4250.           weaker, such  as preferred  color  reproduction.    While  device
  4251.           independent spectral  color reproduction  is  impossible,  device
  4252.           independent  colorimetric  reproduction  is  possible,  within  a
  4253.           tolerance and within the limits of the gamuts of the devices.  By
  4254.           choosing a  strong criteria  we allow the important objectives of
  4255.           weaker criteria, such as preferred color reproduction, to be part
  4256.           of design packages.
  4257.           
  4258.           Metamerism
  4259.           
  4260.           If two  patches of  color  are  identical  under  one  light  and
  4261.           different under  another, they  are said  to be  metameric pairs.
  4262.           Colorimetric  color  reproduction  is  a  weaker  condition  than
  4263.           spectral color reproduction and hence allows metamerism problems.
  4264.           By standardizing  the viewing  conditions we  can largely finesse
  4265.           the metamerism  problem for  print.   Because television is self-
  4266.           luminous and doesnÆt use spectral absorption, metamerism isnÆt so
  4267.           much a problem.
  4268.           
  4269.           Color Models - xyY Versus Luv, etc.
  4270.           
  4271.           We choose  xyY over  Luv [1]  because XYZ  is  the  international
  4272.           standard for  color specification  and xyY  is  the  chromaticity
  4273.           diagram associated  with XYZ.   Luv is meant for color difference
  4274.           measurement.
  4275.           
  4276.           Ambient Environment And Viewing Surrounds
  4277.           
  4278.           The viewing environment affects how the eye perceives color.  The
  4279.           eye adapts  to a  dark room  and it adapts to a colored surround.
  4280.           While  these   problems  can   be  compensated   for  within  the
  4281.           colorimetric framework  [4], it is much better to finesse them by
  4282.           standardizing.   The design environment should match the intended
  4283.  
  4284.  
  4285.  
  4286.  
  4287.  
  4288.  
  4289.  
  4290.  
  4291.  
  4292.           TIFF 5.0                                          page 65
  4293.           TIFF 5.0                                          page 65
  4294.  
  4295.  
  4296.           viewing environment.   Specifically it should not be a pitch dark
  4297.           room and,  on average,  it should  be of  a neutral  color.   For
  4298.           print, ANSI recommends a Munsell N-8 surface [8].
  4299.           
  4300.           
  4301.           XI. References
  4302.           
  4303.           In particular,  we would  like to mention the work of Stuart Ring
  4304.           of the  Copy Products  Division of the Eastman Kodak Company.  He
  4305.           and  his  colleagues  are  promoting  a  color  data  interchange
  4306.           paradigm.   They are  working closely  with the  ISO 8613 Working
  4307.           Group [7].
  4308.           
  4309.           [1]  Color Data  Interchange Paradigm,  Eastman Kodak, Rochester,
  4310.           New York, 7 December 1987.
  4311.           
  4312.           [2]  Color  Reproduction   and  Illumination  Models,  Roy  Hall,
  4313.           International Summer  Institute:   State of  the Art  in Computer
  4314.           Graphics, 1986.
  4315.           
  4316.           [3]  CIE   Colorimetry:    Official   Recommendations    of   the
  4317.           International Commission on Illumination, Publication 15-2, 1986.
  4318.           
  4319.           [4]  Color Science:  Concepts and  Methods, Quantitative Data and
  4320.           Formulae, Gunter  Wyszecki, W.S.  Stiles, John  Wiley  and  Sons,
  4321.           Inc., New York, New York, 1982.
  4322.           
  4323.           [5]  Color Monitor  Colorimetry, SMPTE  Recommended  Practice  RP
  4324.           145-1987.
  4325.           
  4326.           [6]  Color Temperature  for  Color  Television  Studio  Monitors,
  4327.           SMPTE Recommended Practice RP 37.
  4328.           
  4329.           [7]  Office   Document   Architecture   (ODA)   and   Interchange
  4330.           Format_Addendum on Colour, ISO 8613 Working Draft.
  4331.           
  4332.           [8]  ANSI Standard PH 2.30-1985.
  4333.           
  4334.           [9]  The Reproduction  of Colour  in  Photography,  Printing  and
  4335.           Television, R.  W. G.  Hunt, Fountain  Press, Tolworth,  England,
  4336.           1987.
  4337.           
  4338.           [10] Raster  Graphics   Handbook,  The  Conrac  Corporation,  Van
  4339.           Nostrand Reinhold  Company, New  York,  New  York,  1985.    Good
  4340.           description of gamma.
  4341.           
  4342.           
  4343.           
  4344.  
  4345.  
  4346.  
  4347.  
  4348.  
  4349.  
  4350.  
  4351.  
  4352.  
  4353.  
  4354.  
  4355.  
  4356.  
  4357.  
  4358.  
  4359.           TIFF 5.0                                          page 66
  4360.           TIFF 5.0                                          page 66
  4361.  
  4362.  
  4363.           Appendix I:  Horizontal Differencing Predictor
  4364.           
  4365.           
  4366.           This appendix,  written after  the release of Revision 5.0 of the
  4367.           TIFF specification,  is still  in draft  form.   Please send  any
  4368.           comments to the Aldus Developers Desk.
  4369.           
  4370.           
  4371.           Revision 5.0  of the  TIFF specification defined a new tag called
  4372.           _Predictor_  that  describes  techniques  that  may  be  used  in
  4373.           conjuction with  TIFF compression  schemes.    We  now  define  a
  4374.           Predictor that  greatly  improves  compression  ratios  for  some
  4375.           images.
  4376.           
  4377.           The horizontal  differencing predictor  is assigned the tag value
  4378.           Predictor = 2:
  4379.           
  4380.           Predictor
  4381.           Tag  = 317 (13D)
  4382.           Type = SHORT
  4383.           N    = 1
  4384.           
  4385.           A predictor  a mathematical operator that is applied to the image
  4386.           data before  the encoding  scheme is  applied.   Currently (as of
  4387.           revision 5.0)  this tag  is used  only with  LZW  (Compression=5)
  4388.           encoding, since  LZW is  probably the  only TIFF  encoding scheme
  4389.           that benefits  significantly from a predictor step.  See Appendix
  4390.           F.
  4391.           
  4392.           1 = No prediction scheme used before coding.
  4393.           2 = Horizontal differencing. See Appendix I.
  4394.           
  4395.           Default is 1.
  4396.           
  4397.           
  4398.           The algorithm
  4399.           
  4400.           The idea  is to  make use  of the  fact that many continuous tone
  4401.           images rarely  vary much  in pixel  value from  one pixel  to the
  4402.           next.   In such  images,  if  we  replace  the  pixel  values  by
  4403.           differences between  consecutive pixels,  many of the differences
  4404.           should be  0, plus  or minus  1, and  so on.   This  reduces  the
  4405.           apparent information  content, and  thus allows LZW to encode the
  4406.           data more compactly.
  4407.           
  4408.           Assuming 8-bit  grayscale  pixels  for  the  moment,  a  basic  C
  4409.           implementation might look something like this:
  4410.           
  4411.                char image[ ][ ];
  4412.                int  row, col;
  4413.           
  4414.                /* take horizontal differences:
  4415.                 */
  4416.                for (row = 0; row < nrows; row++)
  4417.  
  4418.  
  4419.  
  4420.  
  4421.  
  4422.  
  4423.  
  4424.  
  4425.  
  4426.           TIFF 5.0                                          page 67
  4427.           TIFF 5.0                                          page 67
  4428.  
  4429.  
  4430.                     for (col = ncols - 1; col >= 1; col--)
  4431.                          image[row][col] -= image[row][col-1];
  4432.           
  4433.           If we  don_t have 8-bit samples, we need to work a little harder,
  4434.           so that  we can make better use of the architecture of most CPUs.
  4435.           Suppose we  have 4-bit  samples, packed  two to a byte, in normal
  4436.           TIFF uncompressed  (i.e., Compression=1)  fashion.   In order  to
  4437.           find differences,  we want to first expand each 4-bit sample into
  4438.           an 8-bit  byte, so  that we  have one  sample per byte, low-order
  4439.           justified.   We then  perform the  above horizontal differencing.
  4440.           Once the  differencing has  been completed, we then repack the 4-
  4441.           bit differences  two to  a  byte,  in  normal  TIFF  uncompressed
  4442.           fashion.
  4443.           
  4444.           If the  samples are  greater than  8  bits  deep,  expanding  the
  4445.           samples into  16-bit words  instead of 8-bit bytes seems like the
  4446.           best way to perform the subtraction on most computers.
  4447.           
  4448.           Note that we have not lost any data up to this point, nor will we
  4449.           lose any  data later  on.   It  might  at  first  seem  that  our
  4450.           differencing might  turn 8-bit samples into 9-bit differences, 4-
  4451.           bit samples  into 5-bit differences, and so on.  But it turns out
  4452.           that we  can completely  ignore the  _overflow_  bits  caused  by
  4453.           subtracting a  larger number  from a  smaller  number  and  still
  4454.           reverse the  process  without  error.    Normal  twos  complement
  4455.           arithmetic does just what we want.  Try an example by hand if you
  4456.           need more convincing.
  4457.           
  4458.           Up  to  this  point  we  have  implicitly  assumed  that  we  are
  4459.           compressing  bilevel   or  grayscale   images.     An  additional
  4460.           consideration arises in the case of color images.
  4461.           
  4462.           If PlanarConfiguration  is 2,  there is no problem.  Differencing
  4463.           proceeds the same way as it would for grayscale data.
  4464.           
  4465.           If  PlanarConfiguration  is  1,  however,  things  get  a  little
  4466.           trickier.   If  we  didnÆt  do  anything  special,  we  would  be
  4467.           subtracting red  sample values  from green  sample values,  green
  4468.           sample values  from blue  sample values,  and blue  sample values
  4469.           from red sample values, which would not give the LZW coding stage
  4470.           much redundancy  to work  with.   So we  will do  our  horizontal
  4471.           differences with  an offset  of SamplesPerPixel  (3, in  the  RGB
  4472.           case).  In other words, we will subtract red from red, green from
  4473.           green, and  blue from blue.  The LZW coding stage is identical to
  4474.           the SamplesPerPixel=1 case.  We require that BitsPerSample be the
  4475.           same for all 3 samples.
  4476.           
  4477.           
  4478.           Results and guidelines
  4479.           
  4480.           LZW without  differencing works  well  for  1-bit  images,  4-bit
  4481.           grayscale images, and synthetic color images.  But natural 24-bit
  4482.           color images  and some 8-bit grayscale images do much better with
  4483.           differencing.  For example, our 24-bit natural test images hardly
  4484.  
  4485.  
  4486.  
  4487.  
  4488.  
  4489.  
  4490.  
  4491.  
  4492.  
  4493.           TIFF 5.0                                          page 68
  4494.           TIFF 5.0                                          page 68
  4495.  
  4496.  
  4497.           compressed at  all using  _plain_ LZW:  the  average  compression
  4498.           ratio was  1.04  to  1.    The  average  compression  ratio  with
  4499.           horizontal differencing  was 1.40  to 1.  (A compression ratio of
  4500.           1.40 to 1 means that if the uncompressed image is 1.40MB in size,
  4501.           the compressed version is 1MB in size.)
  4502.           
  4503.           Although  the   combination  of   LZW  coding   with   horizontal
  4504.           differencing does  not result  in any  loss of  data, it  may  be
  4505.           worthwhile in  some situations  to give  up some  information  by
  4506.           removing as  much noise  as possible  from the  image data before
  4507.           doing the  differencing, especially  with  8-bit  samples.    The
  4508.           simplest way  to get  rid of noise is to mask off one or two low-
  4509.           order bits  of each 8-bit sample.  On our 24-bit test images, LZW
  4510.           with horizontal differencing yielded an average compression ratio
  4511.           of 1.4 to 1.  When the low-order bit was masked from each sample,
  4512.           the compression  ratio climbed to 1.8 to 1; the compression ratio
  4513.           was 2.4  to 1  when masking  two bits,  and 3.4 to 1 when masking
  4514.           three bits.   Of  course, the  more you  mask, the  more you risk
  4515.           losing useful information along with the noise.  We encourage you
  4516.           to experiment  to find  the best compromise for your device.  For
  4517.           some applications it may be useful to let the user make the final
  4518.           decision.
  4519.           
  4520.           Interestingly, most  of our RGB images compressed slightly better
  4521.           using PlanarConfiguration=1.   One  might think  that compressing
  4522.           the  red,   green,  and   blue   difference   planes   separately
  4523.           (PlanarConfiguration=2) might  give  better  compression  results
  4524.           than  mixing   the  differences   together   before   compressing
  4525.           (PlanarConfiguration=1), but this does not appear to be the case.
  4526.           
  4527.           Incidentally,  we  tried  taking  both  horizontal  and  vertical
  4528.           differences,  but   the  extra   complexity  of   two-dimensional
  4529.           differencing did  not appear  to pay  off for  most of  our  test
  4530.           images.  About one third of the images compressed slightly better
  4531.           with two-dimensional  differencing, about  one  third  compressed
  4532.           slightly worse, and the rest were about the same.
  4533.           
  4534.           
  4535.           
  4536.           
  4537.           
  4538.  
  4539.  
  4540.  
  4541.  
  4542.  
  4543.  
  4544.  
  4545.  
  4546.  
  4547.  
  4548.  
  4549.  
  4550.  
  4551.  
  4552.  
  4553.  
  4554.  
  4555.  
  4556.  
  4557.  
  4558.  
  4559.  
  4560.           TIFF 5.0                                          page 69
  4561.           TIFF 5.0                                          page 69
  4562.  
  4563.  
  4564.           Appendix J:  Palette Color
  4565.           
  4566.           
  4567.           This appendix,  written after  the release of Revision 5.0 of the
  4568.           TIFF specification,  is still  in draft  form.   Please send  any
  4569.           comments to the Aldus Developers Desk.
  4570.           
  4571.           
  4572.           Revision  5.0   of  the   TIFF  specification   defined   a   new
  4573.           PhotometricInterpretation value  called _palette color._  We have
  4574.           been wondering  lately if this additional complexity is worth the
  4575.           implementation expense.   If  not, let_s  drop it before too many
  4576.           people start creating palette color images.
  4577.           
  4578.           
  4579.           The Proposal
  4580.           
  4581.           Instead of a separate palette color image type, there seems to be
  4582.           no compelling reason why palette (mapped) color images should not
  4583.           be stored as _full color_ (usually 24-bit) RGB images.
  4584.           
  4585.           
  4586.           Objections
  4587.           
  4588.           The most  obvious objection is the amount of space required.  But
  4589.           if you  care about how much space the image takes up on disk, you
  4590.           should use  LZW compression,  which is  ideally  suited  to  most
  4591.           palette color  images.   (LZW compresses  most paint-type palette
  4592.           color images  5:1 or  more.)   And if you use LZW compression, it
  4593.           turns out  that palette  color images stored as full color images
  4594.           compress to  almost exactly the same size as palette color images
  4595.           stored as  palette color  images.  That is, with LZW compression,
  4596.           there is  no penalty  for storing  palette color  images as  full
  4597.           color RGB  images.   The resulting  file may  be  a  few  percent
  4598.           larger, but  it will not be three times as large.  See Appendix F
  4599.           for more information on how LZW works.
  4600.           
  4601.           Another objection  might be  that an  application might  want  to
  4602.           process the  image differently  if it is _really_ a palette color
  4603.           image. But  we can easily add auxiliary information that can help
  4604.           a TIFF  reader to quickly categorize color images if it wants to.
  4605.           See the _New tags_ section below.
  4606.           
  4607.           
  4608.           Benefits
  4609.           
  4610.           It may  be obvious,  but it  is probably  worth discussing why we
  4611.           want  to   abolish   palette   color   images   as   a   distinct
  4612.           classification.
  4613.           
  4614.           The main  problem is  that palette color as a separate type makes
  4615.           life more  hazardous and  confusing for  users.    The  confusion
  4616.           factor is  aggravated because  users already  have to be somewhat
  4617.           aware of  distinctions  between  bilevel,  grayscale,  and  color
  4618.  
  4619.  
  4620.  
  4621.  
  4622.  
  4623.  
  4624.  
  4625.  
  4626.  
  4627.           TIFF 5.0                                          page 70
  4628.           TIFF 5.0                                          page 70
  4629.  
  4630.  
  4631.           images.   Having two  main types of color images is hard for many
  4632.           users to  grasp, and  it is probably not possible to totally hide
  4633.           this complexity  from the user in certain situations.  The hazard
  4634.           level goes  up because some applications may accept palette color
  4635.           but not  full color  images, or  full color but not palette color
  4636.           images, or may accept 8-bit palette color images but not 4-bit or
  4637.           3-bit palette color images.
  4638.           
  4639.           The second  problem is  that writing and maintaining code to deal
  4640.           with an  additional image  type is  somewhat expensive  for  TIFF
  4641.           readers.  The cost of supporting palette color images will depend
  4642.           on the  application, but  we believe  that, in  general, the cost
  4643.           will be  substantial.   It seems  to make  more sense  to put the
  4644.           burden on  TIFF writers to convert palette color images into full
  4645.           color image  form than  to make TIFF readers handle an additional
  4646.           color image  type, since there are more TIFF readers than writers
  4647.           at this point.
  4648.           
  4649.           
  4650.           New tags
  4651.           
  4652.           Here are  some proposed  new tags that can help to classify color
  4653.           images, and  make up  for not  having a  separate  palette  color
  4654.           class.  They are not required for TIFF Class R , but are strongly
  4655.           recommended for  color TIFF  images created by palette-type color
  4656.           paint programs.
  4657.           
  4658.           ColorImageType
  4659.           Tag  = 318 (13E)
  4660.           Type = SHORT
  4661.           N    = 1
  4662.           
  4663.           Gives TIFF  color image  readers a  better idea  of what  kind of
  4664.           color image it is.  There will be borderline cases.
  4665.           
  4666.           1 = Continuous tone, natural image.
  4667.           2 =  Synthetic image, using a greatly restricted range of colors.
  4668.           Such images  are produced  by most  color paint  programs.    See
  4669.           ColorList for a list of colors used in this image.
  4670.           
  4671.           Default is 1.
  4672.           
  4673.           ColorList
  4674.           Tag  = 319 (13F)
  4675.           Type = BYTE or SHORT
  4676.           N    = the  number of  colors that  are used in this image, times
  4677.           SamplesPerPixel
  4678.           
  4679.           A list  of colors that are used in this image.  Use of this field
  4680.           is only  practical for  images containing  a  greatly  restricted
  4681.           (usually  less   than  or   equal  to   256)  range   of  colors.
  4682.           ColorImageType should be 2.  See ColorImageType.
  4683.           
  4684.  
  4685.  
  4686.  
  4687.  
  4688.  
  4689.  
  4690.  
  4691.  
  4692.  
  4693.  
  4694.           TIFF 5.0                                          page 71
  4695.           TIFF 5.0                                          page 71
  4696.  
  4697.  
  4698.           The list  is organized  as an array of RGB triplets, with no pad.
  4699.           The RGB  triplets are  not guaranteed  to be  in  any  particular
  4700.           order.   Note that the red, green, and blue components can either
  4701.           be a  BYTE or  a SHORT  in length.  BYTE should be sufficient for
  4702.           most applications.
  4703.           
  4704.           No default.
  4705.           
  4706.  
  4707.  
  4708.  
  4709.  
  4710.  
  4711.  
  4712.  
  4713.  
  4714.  
  4715.  
  4716.  
  4717.  
  4718.  
  4719.  
  4720.  
  4721.  
  4722.  
  4723.  
  4724.  
  4725.  
  4726.  
  4727.  
  4728.  
  4729.  
  4730.  
  4731.  
  4732.  
  4733.  
  4734.  
  4735.  
  4736.  
  4737.  
  4738.  
  4739.  
  4740.  
  4741.  
  4742.  
  4743.  
  4744.  
  4745.  
  4746.  
  4747.  
  4748.  
  4749.  
  4750.  
  4751.  
  4752.  
  4753.  
  4754.  
  4755.  
  4756.  
  4757.  
  4758.